ID | DATE | col1 |
---|---|---|
1 | 01-01-2022 | apple |
1 | 01-02-2022 | orange |
It's been a while since I've worked with sql (using oracle fyi). If I want to pull unique ID's with the latest Date (in this case only the second row should be pulled in the result), how can I do that?
I tried:
SELECT ID, MAX(DATE), col1
FROM table
GROUP BY ID
Now this doesn't work because I need to aggregate col1 in the SELECT or throw it in the GROUP BY. If I throw it in the GROUP BY, I'll get both rows in the result, right? But I also don't see the point in aggregating col1 if I want the row based on max(date). Am I missing something here?