GROUP BY on multiple columns

Posted by Tams on Stack Overflow See other posts from Stack Overflow or by Tams
Published on 2012-09-12T09:23:51Z Indexed on 2012/09/12 9:38 UTC
Read the original article Hit count: 166

Filed under:
|

I have a table that looks like the following -

  Id     Reference     DateAttribute1    DateAttribute2
  1      MMM005         2011-09-11       2012-09-10 
  2      MMM005         2012-06-13       2012-09-10 
  3      MMM006         2012-08-22       2012-09-10 
  4      MMM006         2012-08-22       2012-09-11 

I have handle to the id values. I would like to query such that I get the following result

  Id     Reference     DateAttribute1    DateAttribute2
  2      MMM005         2012-06-13       2012-09-10 
  4      MMM006         2012-08-22       2012-09-11 

I would like my result to be grouped by reference and then 'DateAttribute1' and then 'DateAttribute2' as such - DateAttribute1 has a priority over DateAttribute2 as you can see above in the result.
How should I write my query to fetch the results in the above manner?

Any solution?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about group-by