Virgil Green wrote:
select * from page_views a where timestamp = (select max(b.timestamp) from
page_views b where a.sessionId=b.sessionId group by sessionId)
A couple of nitpicks:
1. 'group by sessionId' is unnecessary, because we know that each
execution of the subquery is restricted to one sessionId.
2. Subqueries work only in MySQL 4.1 and later, and sks didn't say which
version of MySQL he/she is using. I don't know how one could do this
type of query without using a correlated subquery.
Sks may have to do this in multiple queries:
select max(timestamp) as maxtimestamp, sessionId
from page_views group by sessionId
then loop through that result set:
select * from page_views
where sessionId = ? and timestamp = ?
Bill K.