Hopefully thi开发者_开发知识库s is pretty simple, but I'm having some trouble. I have a table that has multiple fields but basically the two that matter are ID and year. A single ID can exist in many years. How do I set up a select statement (Which I'm ultimately using in a join in another statement) so that I can retrieve all of the distinct IDS with no duplicates for the top year that they exist for?
If there is a set of records like this:
ID - Year
55 - 2000
55 - 2001
56 - 2000
56 - 2002
So basically I want something like this returned:
55 - 2001
56 - 2002
Help?
SELECT ID, MAX(Year) FROM MyTable GROUP BY ID
References:
- SELECT (Transact-SQL)
- GROUP BY (Transact-SQL)
- Aggregate Functions (Transact-SQL)
- MAX (Transact-SQL)
精彩评论