How To Group By In Sql By Largest Date (order By A Group By)
I have the following database table Here is my sample data I have for it. What I am trying to figure out how to do is how to write a query to select all apntoken for userid='20'
Solution 1:
My favorite way to construct this SQL is to use a not exists
clause like so:
SELECT apntoken,deviceid,created
FROM `distribution_mobiletokens` as dm
WHERE userid='20'
and not exists (
select 1
from `distribution_mobiletokens`
where userid = '20'
and deviceid = dm.deviceid
and created > dm.created
)
Post a Comment for "How To Group By In Sql By Largest Date (order By A Group By)"