In my application a user can login and then share something. I'd like to get their latest login information relative to the date that they shared something (e.g., the MAX
login date that was before than the share date)
I have two tables (they are related by csh.actor = ul.user_id
):
CollectionShares (csh)
| id | actor | shareDate
UsersLogins (ul)
| id | user_id | httpReferer | browser | ipAddress | loginDate
One of my attempts:
SELECT
csh.shareDate AS shareDate,
ul.httpReferer AS httpReferer,
ul.browser AS browser,
ul.ipAddress AS ipAddress,
max(ul.loginDate) AS nearestLastLoginDate
FROM collectionsharehistory csh
JOIN userslogins ul ON
csh.actor = ul.user_id
AND
ul.loginDate <= csh.shareDate
GROUP BY csh.id;
This actually seems to be getting the right ul.loginDate
, but the other ul
columns are incorrect and do not seem to actually match up with the returned loginDate
.