user_id | user_destination | user_date_out | user_date_in | user_purpose | uid
0095 | NYC | 2010-11-25 | 2010-11-26 | Work | 1
0105 | Seattle | 2010-11-15 | 2010-11-20 | Work | 2
0095 | Home | 2010-11-10 | 2010-11-11 | Personal | 3
0123 | Nashville | 2010-11-10 | 2010-11-12 | Doctober | 4
I have the above data in a MySQL table. I need a query that will output the row if it is the most recent user_date_out for that user_id. Hard to explain, but the rows that should be displayed via the query are uid 2,3 and 4 (UID 1 would fall off because the user_date_out is "older" than UID 3 for the same user). Can anyone help me with this? Thanks in advance!
EDIT: I solved it by using the following query:
SELECT *
FROM `table`
WHERE `uid` = (
SELECT `uid`
FROM `table` as `alt`
WHERE `alt`.`user_id` = `table`.`user_id`
ORDER BY `user_date_out`
LIMIT 1
)
ORDER BY `user_date_out`