I have kind of a timesheet table and I have a column for the row ID, a column for the username, a column for that status (in/out), and then a timestamp column.
I want to select the username, then the time in and the subsequent time out. I figured out a query that will select the username, then the time in and all other out times after that, but I only want the next out time.
Here is what I have so far -
SELECT t1.username, t1.status, t1.tstamp, t2.status, t2.tstamp
FROM ta_timesheet AS t1
JOIN ta_timesheet AS t2 ON t1.username = t2.username
WHERE t1.status = "IN" AND t2.status = "OUT" AND t1.tstamp < t2.tstamp
ORDER BY t1.ts_id ASC
For example, this currently displays -
user1 - in - 2011-05-18 08:00:30 - out - 2011-05-18 09:31:25
user1 - in - 2011-05-18 08:00:30 - out - 2011-05-19 10:00:45
user1 - in - 2011-05-18 08:00:30 - out - 2011-05-21 14:02:25
user1 - in - 2011-05-19 08:03:10 - out - 2011-05-19 10:00:45
user1 - in - 2011-05-19 08:03:10 - out - 2011-05-21 14:02:25
user1 - in - 2011-05-21 10:58:02 - out - 2011-05-21 14:02:25
I want it to show -
user1 - in - 2011-05-18 08:00:30 - out - 2011-05-18 09:31:25
user1 - in - 2011-05-19 08:03:10 - out - 2011-05-19 10:00:45
user1 - in - 2011-05-21 10:58:02 - out - 2011-05-21 14:02:25