I have the following table:
id time text otheridentifier ------------------------------------------- 1 6 apple 4 2 7 orange 4 3 8 banana 3 4 9 pear 3 5 10 grape 2
What I want to do is select the last 3 entries (by time) whose otheridentifier is different. Thus, in this case, the result will be id s: 5, 4, and 2.
id = 3 will be skipped because there is a later entry with the same otheridentifier field.
Here is what I tried to do:
SELECT * FROM `table` GROUP BY (`otheridentifier`) ORDER BY `time` DESC LIMIT 3
However, in the end I get the lines id = 5, 3 and 1 instead of 5, 4, 2, as expected.
Can someone tell me why this query will not return what I expected? I tried changing ORDER BY to ASC, but it just permutes the returned rows to 1, 3, 5.
mysql sql-order-by group-by
ash May 29 '09 at 5:20 a.m. 2009-05-29 05:20
source share