FROM子句中的SQL语法错误

时间:2012-08-20 20:19:54

标签: sql

以下是我遇到错误的代码:

FROM
    IndexPID
    INNER JOIN Demographics ON
        IndexPID.NDoc_Number = Demographics.NDoc_Number,
    PatientSupply
    INNER JOIN Demographics ON
        PatientSupply.NDocNum = Demographics.NDoc_Number

我也是这样试过的:

FROM
    IndexPID, PatientSupply
    INNER JOIN Demographics ON
        IndexPID.NDoc_Number = Demographics.NDoc_Number
    INNER JOIN Demographics ON
        PatientSupply.NDocNum = Demographics.NDoc_Number

但没有雪茄。有谁告诉我我做错了什么?

4 个答案:

答案 0 :(得分:4)

如果发布整个SQL,

会更容易!

尝试

FROM
IndexPID
INNER JOIN Demographics ON
    IndexPID.NDoc_Number = Demographics.NDoc_Number
INNER JOIN PatientSupply ON
    PatientSupply.NDocNum = Demographics.NDoc_Number

答案 1 :(得分:4)

你非常接近:

FROM IndexPID
INNER JOIN Demographics 
   ON IndexPID.NDoc_Number = Demographics.NDoc_Number
INNER JOIN PatientSupply
   ON Demographics.NDoc_Number = PatientSupply.NDocNum

答案 2 :(得分:2)

您在这里以奇怪的方式混合隐式(逗号分隔)和显式JOIN。它应该如下所示,仅使用显式INNER JOIN,表名或ON子句之间没有逗号:

FROM
  IndexPID
  INNER JOIN Demographics 
    ON IndexPID.Ndoc_Number = Demographics.NDoc_Number
  INNER JOIN PatientSupply 
    ON PatientSupply.NDocNum = Demographics.NDoc_Number

答案 3 :(得分:1)

您使用内部联接,因此您可以使用:

FROM Demographics
inner join IndexPID on Demographics.NDoc_Number=IndexPID.NDoc_Number
inner join PatientSupply on Demographics.NDoc_Number=PatientSupply.NDocNum