Hello,
I am trying to develop a script to show the current users on a web-site. It combines two tables. One table has the sessions (used for login tracking) and the second for site hits and the pages accessed. The query looks like
SELECT sessions.id,sessions.ip,sessions.lastaccessed,hits.page FROM sessions,hits WHERE sessions.id=hits.session_id
Since there are more than one hit / session, I must GROUP BY sessions.id
SELECT sessions.id,sessions.ip,sessions.lastaccessed,hits.page FROM sessions,hits WHERE sessions.id=hits.session_id GROUP BY sessions.id
But, the problem is, the query results show the very first hit and not the most recent. I have tried
SELECT sessions.id,sessions.ip,sessions.lastaccessed,hits.page FROM sessions,hits WHERE sessions.id=hits.session_id GROUP BY sessions.id ORDER BY hits.datetime [results do not change, either DESC or ASC]
Essentially, I am trying to get the results, ordered by session id, then by the latest hit, then get the top row per session.
Any help or suggestions are greatly appreciated. Thanks for your time