I have a simple table called ‘message’ consisting of an ‘id’ column and a ‘date’ column. There can be multiple id’s with the same value. I’m looking for a query that returns up to three of each id, and of those three they must be the ones with the greatest dates.
So the query would produce something like this:
id | date
--- -------------------
36 2011-04-01 08:41:19
36 2011-04-17 08:05:18
36 2011-04-17 18:48:49
39 2011-03-31 05:45:15
39 2011-03-31 05:50:07
39 2011-03-31 05:56:23
41 2011-04-11 07:02:27
41 2011-04-19 02:31:31
41 2011-04-19 02:32:53
etc...
I’ve been having trouble figuring this out.
1 Answer