Skip to main content
1 of 2
user3533235
  • 612
  • 3
  • 14

Delete query and left join with JDatabaseQuery doesn't work

I'am trying to convert delete query with left join to use JDatabaseQuery, but i encounter an issue in the query. The query that i trying to convert and which works is the following :

$db->setQuery("DELETE u FROM #__mycomponent_users AS u
                LEFT JOIN #__users AS ju ON u.userid=ju.id
                WHERE ju.username IS NULL"); 

I have converted it to JDatabaseQuery, with the following code :

$db->getQuery(true)
            ->delete($db->quoteName('#__mycomponent_users', 'u'))
            ->leftJoin($db->quoteName('#__users', 'ju') . ' ON u.userid=ju.id')
            ->where('ju.username IS NULL');
$db->setQuery($query);

In this it return the following error :

Syntax error near 'AS u LEFT JOIN jt5il_users AS ju ON u.userid=ju.id WHERE ju.username IS NUL'

So how to make working the query by using JDatabaseQuery ?

Thanks by advance

user3533235
  • 612
  • 3
  • 14