1

我有一个查询

SELECT * FROM Issue I, Condition C, Result R, Status S      
            LEFT JOIN Issue as i1 ON C.ID = i1.ConditionID
            LEFT JOIN Issue as i2 ON R.ID = i2.ResultID
            LEFT JOIN Issue as i3 ON S.ID = i3.StatusID 
            WHERE I.ID = 452

这给了我错误消息:

无法绑定多部分标识符“C.ID”。
无法绑定多部分标识符“R.ID”。

我希望得到如下结果:

身份证| 问题名称| 条件ID| 结果ID| 状态ID| 身份证| 条件名称| 身份证| 结果名称| 身份证| 状态名称

4

5 回答 5

2

我假设您没有使用MySQL Server. 尝试这个:

SELECT * 
FROM Issue I, Condition C, Result R, Status S      
     LEFT JOIN Issue as i1 ON C.ID = i1.[Condition ID]
     LEFT JOIN Issue as i2 ON R.ID = i2.[Result ID]
     LEFT JOIN Issue as i3 ON S.ID = i3.StatusID 
WHERE I.ID = 452

或者

SELECT *
FROM Issue I LEFT JOIN Condition C ON C.ID = I.ConditionID
     LEFT JOIN Result    R ON R.ID = I.ResultID
     LEFT JOIN Status    S ON S.ID = I.StatusID
WHERE I.ID = 452
于 2012-04-05T07:21:05.237 回答
2

我会尝试

SELECT *
FROM Issue I
LEFT JOIN Condition C ON C.ID = I.ConditionID
LEFT JOIN Result    R ON R.ID = I.ResultID
LEFT JOIN Status    S ON S.ID = I.StatusID
WHERE I.ID = 452
于 2012-04-05T07:19:51.180 回答
1

首先,关系“I”与您发布的查询中的任何其他关系之间没有 JOIN,因此您最终将在此处获得笛卡尔连接。

使用老式连接查询可能如下所示:

SELECT *
  FROM Issue I, Condition C, Result R, Status S
 WHERE I.ConditionID = C.ID
   AND I.ResultID = R.ID
   AND I.StatusID = S.ID
   -- the filter comes here
  AND I.ID = 42;

使用 ANSI 连接语法:

SELECT *
  FROM Issue I
    LEFT JOIN Condition C ON C.ID = I.ConditionID
    LEFT JOIN Result R ON R.ID = I.ResultID
    LEFT JOIN Status S ON S.ID = I.StatusID
 -- the filter comes here
 WHERE I.ID = 42;
于 2012-04-05T07:29:20.673 回答
1
SELECT * FROM Issue I, Condition C, Result R , Status S      
                                             ^---- You missing this
            LEFT JOIN Issue as i1 ON C.ID = i1.Condition ID
            LEFT JOIN Issue as i2 ON R.ID = i2.Result ID
            LEFT JOIN Issue as i3 ON S.ID = i3.StatusID 
            WHERE I.ID = 452
于 2012-04-05T07:17:55.543 回答
0

您的查询中有错字:

Result R [comma is needed here] Status S
于 2012-04-05T07:16:46.577 回答