Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Unanswered: Multiple distinct fields

    Hello,
    Take the following table for example:
    -----------------------------------
    ----ID-----------|-----YEAR-------
    | 0 ------------------ 2008
    | 1 ------------------ 2008
    | 2 ------------------ 2008
    | 3 ------------------ 2009
    | 4 ------------------ 2009
    | 5 ------------------ 2009
    | 6 ------------------ 2009
    -----------------------------------

    What I need to do is select one full row per year. That is with both ID and YEAR, and just any old row (ID doesn't matter).

    select distinct year from table;

    works, but does not include the ID. And:

    select distinct year, id from table;

    Has duplicates of year...

    Any ideas?

  2. #2
    Join Date
    Sep 2009
    Posts
    64
    Try this ...

    Code:
    SELECT year, id FROM table GROUP BY year

  3. #3
    Join Date
    Sep 2009
    Posts
    64
    Oh I forgot to add ... if you want to get the lowest or the highest ID for the year ... just change id to MAX(id) or MIN(id)

  4. #4
    Join Date
    Sep 2009
    Posts
    2
    Wow, well i swear I tried that but apparently not

    Thanks. group by year did the trick.

Posting Permissions

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