I have this data:
ID NAME DATE
3 JOHN 2011-08-08
2 YOKO 2010-07-07
1 JOHN 2009-06-06
Code (for SQL Server 2005):
DECLARE @TESTABLE TABLE (id int, name char(4), date smalldatetime)
INSERT INTO @TESTABLE VALUES (3, 'JOHN', '2011-08-08')
INSERT INTO @TESTABLE VALUES (2, 'YOKO', '2010-07-07')
INSERT INTO @TESTABLE VALUES (1, 'JOHN', '2009-06-06')
I want to get, for each NAME, the ID that has the most recent DATE. Like this:
3 JOHN 2011-08-08
2 YOKO 2010-07-07
What is the most elegant way of accomplishing this?
below is a possible solution:
Try to avoid reserved words (and vague column names) like
[DATE]
...