I currently got this query:
SELECT
`users_sessions`.`userid` `users_sessions`.`lastActive` , `users`.`firstname`
FROM
`users_sessions` , `users`
WHERE
`users_sessions`.`lastActive` >= DATE_SUB( NOW( ) , INTERVAL 60 MINUTE )
AND
`users`.`uidNumber` = `users_sessions`.`userid`
It selects all sessions where lastActive
is 1 hour ago maximum. Now, as users can have multiple sessions at the same time, I only want to select the one with the biggest lastActive
value.
I know that I somehow got to use GROUP BY users_sessions.userid
and then select the entry with the biggest lastActive
.
How can I do this properly?