Im trying to implement delete code with LEFT JOIN in Joomla 2.5:
$cid = JRequest::getVar('cid', array(), 'post', 'array');
$query = $db->getQuery(true);
$query->delete($db->quoteName('table1').' AS t1');
$query->leftJoin($db->quoteName('table2').
' AS t2 ON t2.table_1_id = t1.id ');
$query->where(array('t1.id IN ('. implode(',', $cid).')'));
$db->setQuery($query);
try {
$db->query();
} catch (Exception $e) {
echo $e->getMessage();
}
What I get is:
DELETE FROM `table1` AS t1
LEFT JOIN `table2` AS t2 ON t2.table_1_id = t1.id
WHERE t1.id IN (48)
This SQL query is incorrect. What I need is:
DELETE t1.*,t2.* FROM `table1` AS t1
LEFT JOIN `table2` AS t2 ON t2.table_1_id = t1.id
WHERE t1.id IN (48)
So how I should change Joomla query to get the right SQL query? Any ideas?
I have been working with Joomla for a long time now. According to my Joomla knowledge you can’t accomplish what you are trying to do
$query->delete(). Since your query is a bit tricky it can be executed using below method.