1

我只想知道如何在学说2中做这样的事情

select 
    e 
from 
    \Entity e 
where 
    e.field1, e.field2 NOT IN (select e2.field1, e2.field2 from \Entity e2 where condition )

当我这样做或者我用括号括起来这两个字段时,我得到了一个错误,比如:

QueryException: [Syntax Error] line 0, col 136: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','

或者:

QueryException:[语法错误]第 0 行,第 135 列:错误:预期 =、<、<=、<>、>、>=、!=、得到“,”

PHP代码:

$query = $this->_em->createQuery('
  SELECT r FROM LibrairieBundle\Entity\Reseau r 
  WHERE ( r.client1 = :me or r.client2 = :me ) and r.confirme = 1 
  and (r.client2, r.client1) not in (
    select s.clientFrom, s.clientObject from LibrairieBundle\Entity\SuggestClient s 
    where s.clientTo = :cible 
  )
');
4

1 回答 1

1

将 where 子句分开。

SELECT 
    e 
FROM 
    \Entity e 
WHERE 
    e.field1 NOT IN (SELECT e2.field1 FROM \Entity e2 WHERE condition ) AND
    e.field2 NOT IN (SELECT e3.field2 FROM \Entity e3 WHERE condition )
于 2013-05-05T02:18:01.523 回答