GROUP BY on multiple columns
- by Tams
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?