1

我有 3 个具有 id 的实体 Patient、具有 id 的 Workers、Professional 和 PatientDeclaration 以及 Patient_id(fk) 和 workers_id(fk)。当我有 Patient_id 和专业时,我想从 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 
4

1 回答 1

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)
于 2013-02-08T19:36:52.843 回答