DQL外连接问题

时间:2014-02-20 20:10:25

标签: php sql symfony doctrine dql

这是我的问题:

SELECT r.pLastName, r.pFirstName, r.ppLocation, a.createdDate, a.appointmentDate, a.hour, a.minute, a.ampm, p.firstName, p.lastName, a.reason, pl.firstName as oncologyPhysicianFirstName, pl.lastName as oncologyPhysicianLastName
FROM MainReferralCaptureBundle:Appointment a, MainReferralCaptureBundle:Referral r, MainReferralCaptureBundle:Physician p
RIGHT OUTER JOIN MainReferralCaptureBundle:PhysicansLocations pl WITH pl.physicansLocationsId = r.ppName
WHERE a.referralId = r.id
AND r.submittedBy = :user
AND r.rpId = p.id
ORDER BY a.appointmentDate DESC

我收到以下错误:

QueryException: [Syntax Error] line 0, col 366: Error: Expected end of string, got 'RIGHT'

如果我这样做:

SELECT r.pLastName, r.pFirstName, r.ppLocation, a.createdDate, a.appointmentDate, a.hour, a.minute, a.ampm, p.firstName, p.lastName, a.reason, pl.firstName as oncologyPhysicianFirstName, pl.lastName as oncologyPhysicianLastName
        FROM MainReferralCaptureBundle:Appointment a, MainReferralCaptureBundle:Referral r, MainReferralCaptureBundle:Physician p
        LEFT OUTER JOIN MainReferralCaptureBundle:PhysicansLocations pl WITH pl.physicansLocationsId = r.ppName
        WHERE a.referralId = r.id
        AND r.submittedBy = :user
        AND r.rpId = p.id
        ORDER BY a.appointmentDate DESC

我明白了:

ORA-00904: "R0_"."PP_NAME": invalid identifier

我不确定发生了什么。 ppName是有效的标识符。请注意,我使用Oracle作为我的后端。

1 个答案:

答案 0 :(得分:0)

发现我必须更改FROM子句中的顺序:

FROM MainReferralCaptureBundle:Appointment a, MainReferralCaptureBundle:Physician p, MainReferralCaptureBundle:Referral r

现在一切正常。