如何创建(可能)嵌套查询?

时间:2013-02-08 12:28:56

标签: doctrine doctrine-orm

我有3个实体患有身份证,患有身份证,职业和患者声明的患者患有患者_id(fk)和workers_id(fk)。当我有耐心和专业时,我想从PatientDeclaration获得workers_id。像这样的东西,

'SELECT c FROM SurgeryPatientBundle:PatientDeclaration c WHERE c.patient = ?1 AND c.patient =(SELECT w  FROM SurgeryWorkersBundle:Workers  WHERE p.profession = ?2)'

我认为我已经创建了嵌套查询? 编辑 解决了我做出不同的查询

SELECT w.id FROM SurgeryWorkersBundle:Workers w JOIN w.patientdeclaration p WHERE w.profession = ?1 AND p.patient = ?2 

1 个答案:

答案 0 :(得分:0)

您可以使用子查询

SELECT 
    c 
FROM 
    SurgeryPatientBundle:PatientDeclaration c 
JOIN
    c.patient p
WHERE 
    p = ?1 
    AND 
    p.id IN (SELECT w.id FROM SurgeryWorkersBundle:Workers  WHERE p.profession = ?2)