I have a problem with this SQL Grouping.
If i have a table with 3 columns. Key is a unique key for every record. Type is the type of record and Version is the version of the type.
ID Type Version
------------------------
1 A 200
2 A 100
3 B 200
4 B 200
5 B 100
I need to get 1 row for each version of each type
so it would look something like
ID Type Version
------------------------
1 A 200
2 A 100
3 B 200
5 B 100
I know I need to group by the Type and version but I cant seem to figure out how to get the unique key for each Type and Version since they are on the same table
SELECT Type, Version FROM TableName GROUP BY Type, Version
Gets me all the unique Types and Versions, but I cant figure out how to finish off the query.
you mean the unique ID?
you need to use an aggregation function like
MAX, MIN, SUM, AVGyou cant get an unique value. Think about it, if you have:
you want only one row with
but whats the logic to define the ID between 1,2 and 3? It isnt unique. That’s why you need a
MAXorMINor any other aggregation function