How do I turn this left join query:
select advertisercontest.*, advertiseraccount.advertiserid, advertiseraccount.companyname
from advertisercontest
left join advertiseraccount on advertiseraccount.loginid = advertisercontest.loginid
where advertisercontest.golive is not NULL;
into a left join in Zend?
LEFT JOIN SyntaxON table1.column_name = table2.column_name; Note: In some databases LEFT JOIN is called LEFT OUTER JOIN.
The LEFT JOIN command returns all rows from the left table, and the matching rows from the right table. The result is NULL from the right side, if there is no match.
The conditions in the ON clause of a LEFT JOIN , when unmet, join the first table's row with null values replacing a row from the second table. If those conditions appear in the WHERE clause, they exclude the first row when unmet. This effectively converts your LEFT JOIN into an ordinary inner JOIN .
You could do as follows:
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select();
$select->from('advertisercontest', '*')
->joinLeft(
'advertiseraccount',
'advertiseraccount.loginid = advertisercontest.loginid',
array('advertiseraccount.advertiserid', 'advertiseraccount.companyname')
)
->where('advertisercontest.golive is not NULL');;
$result = $db->fetchAll($select);
var_dump($result);
Here is the Zend_Db_Select documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With