RE: retrieving last record for all distinct users

2004-03-20 Thread Matt Chatterley
'mysql' Subject: RE: retrieving last record for all distinct users Making the assumption that you are running a version of MySQL which supports subqueries, I believe you could use: SELECT Login, TimeStamp, IP FROMSessions S INNER JOIN ( SELECT M

RE: retrieving last record for all distinct users

2004-03-20 Thread Matt Chatterley
Making the assumption that you are running a version of MySQL which supports subqueries, I believe you could use: SELECT Login, TimeStamp, IP FROMSessions S INNER JOIN ( SELECT MAX(TimeStamp) TimeStamp, Login FROMSessions

Re: retrieving last record for all distinct users

2004-03-19 Thread Michael Stassen
First, since you group by LOGIN, you don't need DISTINCT. The problem is that GROUP BY is designed for use with aggregate functions, not individual rows. So which values of SESSION_ID, IP, and TIMESTAMP you should get is undefined. The manual gives 3 solutions to this problem: