Write “NOT IN” in Doctrine Query Language

前端 未结 2 1061
无人及你
无人及你 2021-01-20 02:55

I have two tables company(id, ...) and company_has_wtax(company_id, ....). I need to get all companies that are not in company_has_wtax

2条回答
  •  既然无缘
    2021-01-20 03:00

    Try this :

    $em = $this->getDoctrine()->getManager();
    
    $query = $em->createQuery('SELECT * FROM YourBundle\Entity\Company c WHERE c.id NOT IN (SELECT c2.company_id FROM YourBundle\Entity\Company_has_wtax c2)');
    
    $companies = $query->getResult(); // array of Company objects
    

提交回复
热议问题