MySQL - strange return for select clause
Question
Why does the following clause does not return, for each userId, it's last connection date ?
I have 31 distinct userids in the table, each one with many dates...
select userid, date from connections group by userid having date = max(date)
Solution
Why are you adding the having
qualifier? If you want max date for each user's last connection try this:
select userid, max(date) from connections group by userid;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow