[thelist] mysql - group by & order by
Joe Flintham
list at menticulture.com
Sun Dec 7 06:55:37 CST 2008
Brian Cummiskey wrote:
> Joe Flintham wrote:
>
>
>> GROUP BY s_group
>> ORDER BY s_timeStamp DESC
>>
>
> try
>
> group by s_group
> having max(s_timestamp)
>
Thanks for the suggestion Brian. Unless, I'm missing something, I think
this still suffers from the GROUP BY priority. I've found a solution
that involves a subselect - I don't know if anyone knows of a simpler
approach?
SELECT A. *
FROM tbl A
INNER JOIN (
SELECT s_group, MAX(s_timeStamp ) AS mostRecent
FROM tbl
GROUP BY s_group
) B
ON A.s_group = B.s_group
AND A.s_timeStamp = B.mostRecent
ORDER BY A.s_timeStamp DESC
Thanks
Joe
More information about the thelist
mailing list