I can’t seem to get this one. So I have a table like this:
RowID UserID Type Data
1 A A 1
2 A A 2
3 A B 1
4 A B 2
5 B A 1
6 B A 2
7 B B 1
8 B B 2
And I need to group this table by UserID and Type and then return the RowID for the record in each group that holds the MIN value in the Data column.
So for my result set would be:
1
3
5
7
For SQL Server >= 2005, you can do:
SQL Fiddle Example
For SQL Server < 2005, you can do:
SQL Fiddle Example