I have the following table.
---------------------------------------------
check_id | action_id | user_id | dt |
---------------------------------------------
1 | 1 | 6 | 2011-09-17 |
2 | 1 | 6 | 2011-09-18 |
3 | 3 | 6 | 2011-09-19 |
4 | 3 | 6 | 2011-09-20 |
---------------------------------------------
I would like to query this table and get the following result.
-----------------------------------------------
action_id | user_id | dt_start | dt_end |
-----------------------------------------------
1 | 6 | 2011-09-17 | 2011-09-18 |
3 | 6 | 2011-09-19 | 2011-09-20 |
-----------------------------------------------
So I'm using the following query.
$checks->select()
->from(array('c1' => 'checks'), array('dt as dt_start')
->joinLeft(array('c2' => 'checks'), 'c1.action_id = c2.action_id', array('dt as dt_end')
->where('c1.user_id = ?', $userId)
->group('c1.action_id')
But this gives me the following result.
-----------------------------------------------
action_id | user_id | dt_start | dt_end |
-----------------------------------------------
1 | 1 | 2011-09-17 | 2011-09-17 |
1 | 3 | 2011-09-19 | 2011-09-19 |
-----------------------------------------------
Can someone tell me what I am doing wrong?