MySQL Forums
Forum List  »  General

Need help with SELECT with GROUP and LIMIT
Posted by: Antonio Kurinski
Date: April 25, 2005 05:15PM

Hi,

I have site login log table and need to find LAST TWO logins for EACH user.
So, log table looks like:

+------------+--------+
| date | user |
+------------+--------+
| 2005.02.01 | mike |
| 2005.02.01 | john |
| 2005.02.01 | jenny |
| 2005.02.02 | mike |
| 2005.02.02 | john |
| 2005.02.02 | jenny |
| 2005.02.03 | mike |
| 2005.02.04 | john |
| 2005.02.05 | mike |
| 2005.02.05 | john |
| 2005.02.05 | jenny |
| ... | ... |
+------------+--------+

and result should look like (for EACH user LAST TWO logins):

+------------+--------+
| date | user |
+------------+--------+
| 2005.02.05 | mike |
| 2005.02.05 | john |
| 2005.02.05 | jenny |
| 2005.02.04 | john |
| 2005.02.03 | mike |
| 2005.02.02 | jenny |
+------------+--------+

Thx in advance for any idea how to write query for this!

Options: ReplyQuote


Subject
Written By
Posted
Need help with SELECT with GROUP and LIMIT
April 25, 2005 05:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.