如何将此sql写入doctrine查询语言(DQL)?
SELECT *
FROM service
WHERE service.id NOT IN (SELECT id_service FROM reclamation)
感谢。
答案 0 :(得分:0)
尝试使用不存在:
SELECT *
FROM service
WHERE NOT Exists (SELECT 1 FROM reclamation WHERE id_service = service.id)
答案 1 :(得分:0)
尝试这样做,
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT s
FROM YourBundle:Service s
WHERE s.id NOT IN
( SELECT s.idService FROM YourBundle:Reclamation r )'
)->getResult();
如果值得,你可以使用旧学校的方式! native-sql-with-docrtine
答案 2 :(得分:0)
请参阅链接http://doctrine.readthedocs.org/en/latest/en/manual/dql-doctrine-query-language.html#subqueries
$q = Doctrine_Query::create()
->select('s')
->from('Service s')
->where('s.id NOT IN (SELECT id_service FROM reclamation)
->getQuery()
->getResult();