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: <http://www.mysql.com/doc/en/example-Maximum-column-group-row.html>.

Michael

motorpsychkill wrote:

I have a table SESSIONS with the following fields:

SESSION_ID LOGIN IP TIMESTAMP

I am trying to select the last login record for all distinct users.  The
closest
I can get to is:

select distinct LOGIN,  TIMESTAMP, IP from SESSIONS group by LOGIN order by
TIMESTAMP desc

This kind of works but it does not get the correct IP for the last
TIMESTAMP.  This seems easy enough, but I can't seem to figure this one out
today.  Can anybody see what I'm missing?  Thanks!

-m




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to