I have 2 columns, names and datetime2. I want to select all distinct names with their latest value for mark according to a thrid col, Date.
eg table
name, mark, date
john, 20, 2014-05-17 01:00:01
sally, 30, 2014-05-18 05:00:00
john, 40, 204-05-17 02:00:00
sally, 50, 2014-05-18 04:30:00
result should be -
john, 40, 2014-05-17 02:00:00
sally, 30, 2014-05-18 05:00:00
I tried
SELECT name, Mark
FROM table
GROUP BY name, date
and
select TOP 1 Name, Mark ,date from table group by name, order by date desc