
December 7th, 2012, 02:00 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 2
Time spent in forums: 33 m 55 sec
Reputation Power: 0
|
|
|
Simple query has me stumped!
Guys, it's 8pm and I'm been beating my head against a wall for a while, any chance someone can help me with the simplest thing?
I have a table which stored user ids, event dates and event descriptions, as follows:
userid eventdate eventdesctiption
1 2012-01-01 00:00:00 a
1 2012-01-02 00:00:00 b
1 2012-01-03 00:00:00 c
1 2012-01-04 00:00:00 d
1 2012-01-05 00:00:00 e
1 2012-01-06 00:00:00 f
2 2012-02-01 00:00:00 a
2 2012-02-02 00:00:00 b
2 2012-02-03 00:00:00 c
2 2012-02-04 00:00:00 d
2 2012-02-05 00:00:00 e
2 2012-02-06 00:00:00 f
What I want to select is the latest event for each user, ie:
userid eventdate eventdesctiption
1 2012-01-06 00:00:00 f
2 2012-02-06 00:00:00 f
so:
select userid, eventdesc
from testdb
where eventdate (is the last one for each user)
Any help would be really great, thanks in advance.
PS, sorry for formatting, forum wouldn't allow me to post screenies.
|