SELECT
the MAX
imum of modification_date
for each GROUP
of (A
, B
), then JOIN
back to the original row to get the values (necessary to get the id
column):
SELECT t1.*
FROM Person t1
JOIN
(
SELECT MAX(modification_date) max_date, A, B
FROM Person
GROUP BY A, B
) t2 ON t1.A = t2.A AND t1.B = t2.B AND t1.modification_date = t2.max_date
More simply, if you don't care which id
you get back, and you only want one row even if modification_date
is duplicated, you can just select the MIN
imum value of id
and be done with it:
SELECT MIN(id) id, A, B, MAX(modification_date) modification_date
FROM Person
GROUP BY A, B