I should have paid more attention in relational databases class, so I need some help.
I have a table structured like so (there’s more, but I’m only posting relevant info):
+------------------+-------------+------+-----+-------------------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+-------------+------+-----+-------------------+-------+ | session_id | char(32) | NO | | NULL | | | file | varchar(30) | NO | | NULL | | | access_time | timestamp | NO | | CURRENT_TIMESTAMP | | +------------------+-------------+------+-----+-------------------+-------+`
I want to select the file field of the record with the greatest access_time for each session_id. So pretty much the last page visited in each session.
I’ve tried countless combinations of DISTINCT and the GROUP BY clause, but I can’t seem to wrap my head around it for some reason. I’m using MySQL. Help please.
I know this will work in SQL Server, and it should port to MySQL.