Select statement

  • Table looks like this.

    Id autoincrement ;unique

    age int

    height int

    gender char

    data as follows

    1 4 5 'm'

    2 4 5 'm'

    3 4 5 'm'

    I only want to return 1 row (id) for each set of distinct age,height,gender....

    so here i will get an ID of 3 returned.

     

    Any ideas?

  • SELECT MAX(id) FROM Table GROUP BY age, height, gender

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • And to return a distinct record for each combination of values without pulling an ID.

    SELECT DISTINCT age, height, gender FROM persontable

    I know GilaMonster has a more correct answer but this is a variation that is useful for validation tables or reporting sometimes.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply