Reputation: 2629
I have a query that returns users by first name, last name, user id and a date they've completed an event.
I want the query to only return one row per user, but some users have completed the same event on multiple dates. I can't use a distinct becuase the dates are distinct, and I can't use a group by for the same reason.
how can I have the query return only the latest date on which the event was completed?
Upvotes: 1
Views: 1534
Reputation: 51494
You should use group by
, and do a MAX
on the date field
Something like...
Select firstname, lastname, userid, max(datecompleted)
from events
group by firstname, lastname, userid
depending on your data structure.
Upvotes: 3