I have data like:
id, id2, datetime_created
1, 1, 9/10
1, 2, 9/9
1, 3, 9/8
2, 4, 9/8
2, 5, 9/2
2, 6, 9/1
3, 7, 9/3
3, 8, 9/4
3, 9, 9/5
Expected output:
id, id2
1, 1
2, 4
3, 9
I've tried a number of things, including:
SELECT id, id2, MAX(datetime_created)
FROM table
GROUP BY id2
,
SELECT id, id2, MAX(datetime_created)
FROM table
GROUP BY id, id2
,
SELECT id, id2
FROM table
INNER JOIN (
SELECT MAX(datetime_created), id
FROM table)
This question was not sufficient. The kicker is the GROUP BY
a different field than one of the ones I need without GROUP BY
ing the second field, as this returns too many rows (from my sample dataset, it would return all rows).