Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Location
    Dallas, TX
    Posts
    77

    Unanswered: How to write this query?

    I have table A, which has colums, col1, col2, col3.
    I have table B, which has columns col1,col4, col5,.. which col1 is foreign key of tableA

    I want to select the col1, col2, and min(col4) according to certain criteria

    I write it as select A.col1, A.col2, min(B.col4) from A inner join B on A.col1 = B.col1
    But I got error, if I delete min(b.col4), then I can get result.

    , how do I write this select query?? Thanks a lot.

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    MIN is an aggregate function, therfore, you need to use a GROUP BY on
    col1 & col2.

    select A.col1, A.col2, min(B.col4) from A inner join B on A.col1 = B.col1
    group by A.col1, A.col2
    Inspiration Through Fermentation

  3. #3
    Join Date
    Sep 2004
    Location
    Dallas, TX
    Posts
    77
    got it. thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •