This question is an exact duplicate of:
I am making a simple time in and time out system.. i have 3 pairs of in and outs. p_id(person_id)
TableA
p_id time_id status timestamp
1 1 in 2013-12-18 15:44:09
2 2 in 2013-12-18 16:23:19
1 3 out 2013-12-18 18:31:11
1 4 in 2013-12-18 18:50:11
3 5 out 2013-12-18 19:20:16
1 6 out 2013-12-18 19:50:11
2 7 out 2013-12-18 19:51:19
1 8 in 2013-12-19 07:51:19
1 9 out 2013-12-19 12:00:19
1 10 in 2013-12-19 01:00:19
1 11 out 2013-12-19 05:30:19
1 12 in 2013-12-19 07:51:19
1 13 out 2013-12-19 11:00:19
How can I select the table into Table Result (one row for the same date and the in and out pairs up to the right is ascending according to time_id)? please check this simple example, maybe you have an idea. http://www.sqlfiddle.com/#!2/6dd1f/8
p_id status timestamp status timestamp status timestamp status timestamp status timestamp status timestamp
1 in 2013-12-18 15:44:09 out 2013-12-18 18:31:11 in 2013-12-18 18:50:11 out 2013-12-18 19:50:11
2 in 2013-12-18 16:23:19 out 2013-12-18 19:51:19
3 out 2013-12-18 19:20:16
1 in 2013-12-19 07:51:19 out 2013-12-19 12:00:19 in 2013-12-19 01:00:19 out 2013-12-19 05:30:19 in 2013-12-19 07:51:19 out 2013-12-19 11:00:19
</div>
I do not know exactly how to solve, but I know that what you are looking for is a pivot: read more about in: http://en.wikibooks.org/wiki/MySQL/Pivot_table
I think the best you'll get, using pure SQL is something like this (untested but you get the idea):
SELECT p_id, GROUP_CONCAT(CONCAT(status, " ", timestamp)) inout
FROM TableA
GROUP BY p_id, DATE(timestamp)