Click to See Complete Forum and Search --> : Need Help with Query


Santal_Maluko
June 27th, 2005, 11:48 AM
Hi,

I would like to have some help here

I have 2 tables:
events(eventid, description, userid) -> description can be Checkin or Checkout;

users(userid, username)



I would like to have all the users that their LAST event is CHECKIN

Seems easy but I can't get a query to do this....

Thanks in Advance

Zeb
June 27th, 2005, 10:52 PM
you didn't say what DB you are using, but the following should be pretty close to what you want:

SELECT users.*
FROM events e1, (SELECT MAX(eventID) event FROM events GROUP BY UserId) e2, users
WHERE e1.eventId = e2.event
AND e1.description = "CHECKIN"
AND e1.userId = users.userId

it could probably be more efficient...

Chris_Student
June 28th, 2005, 02:40 PM
Try this:


SELECT userid FROM events
WHERE Last(description) = 'Checkin' or Last(description) = 'Checkout'
GROUP BY userid

cd2sg
June 29th, 2005, 06:54 AM
Try this

SELECT userid FROM events
WHERE Last(description) like 'Check%'
GROUP BY userid