sql - Specify sorting order for a GROUP BY query to retrieve oldest or newest record for each group -
i need recent record each device upgrade request log table. device unique based on combination of hardware id , mac address. have been attempting group by
not convinced safe since looks may returning "top record" (whatever sqlite or mysql thinks is).
i had hoped "top record" hinted @ way of order by
not seem having impact both of following queries returns same records each device, in opposite order:
select exthwid, mac, created upgraderequest group exthwid, mac order created desc select exthwid, mac, created upgraderequest group exthwid, mac order created asc
is there way accomplish this? i've seen several related posts have involved sub selects. if possible, without subselects learn how without that.
try:
select exthwid, mac, max(created) upgraderequest group exthwid, mac
Comments
Post a Comment