Make a self-join:
$db->select()
->from(array('a' => 'my_table'), array())
->join(array('b' => 'my_table'), 'b.Sender = a.Recipient', array('Recipient'))
->where('a.Sender = ?', $id)
Question
I have one question about query in Zend with this data:
+--------+-----------+ | Sender | Recipient | +--------+-----------+ | 1010 | 1011 | | 1011 | 1012 | | 1011 | 1010 | | 1012 | 1011 | | 1012 | 1000 | +--------+-----------+
If I query for 1010
the answer should be 1012
, because 1010
is sender for recipient 1011
and 1011
is sender for recipient 1012
:
1010->1011->1012
If input 1011
the answer should be 1011
, 1000
and 1011
:
1011->1012->1011,1000 1011->1010->1011
How do I query in one line for Zend framework?
Solution
Make a self-join:
$db->select()
->from(array('a' => 'my_table'), array())
->join(array('b' => 'my_table'), 'b.Sender = a.Recipient', array('Recipient'))
->where('a.Sender = ?', $id)