Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a LEFT JOIN in a DELETE QUERY?

Tags:

php

doctrine

Will you give me an example of a delete query that use a left join using Doctrine?

like image 896
Leonardo Avatar asked Jan 21 '23 11:01

Leonardo


1 Answers

It's not possible. See that: http://trac.doctrine-project.org/ticket/2142

You have to use a subquery in the where clause: http://www.doctrine-project.org/documentation/manual/1_2/en/dql-doctrine-query-language:subqueries

Try something like that:

$q = Doctrine_Query::create()
    ->delete('TableB b')
    ->where('b.id NOT IN (SELECT b.id FROM TableB b \
          INNER JOIN b.TableA a WHERE b.date > NOW() AND a.channel_id = 10)')
    ->execute();
like image 65
Sergio Avatar answered Jan 30 '23 13:01

Sergio