这是我的数据库结构
https://docs.google.com/open?id=0B9ExyO6ktYcOenZ1WlBwdlY2R3c
我的SQL查询看起来是这样的
SELECT
u.fullname,
a.id,
a.content,
a.addDT,
a.`right`,
acr.score,
acr.checkDT
FROM
answers a,
users u
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
a.qid = 7
AND u.id = a.uid
GROUP BY
a.`right` DESC
获取错误消息
[Err] 1054 - Unknown column 'a.id' in 'on clause'
我确信A.ID列存在。
我错过了什么?
最佳答案
不能将联接语法与逗号分隔的表语法混合使用。如果要左联接,则需要对其他两个表使用内部联接。
SELECT
u.fullname,
a.id,
a.content,
a.addDT,
a.`right`,
acr.score,
acr.checkDT
FROM
answers a
INNER JOIN users u ON u.id = a.uid
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
a.qid = 7
GROUP BY
a.`right` DESC
这也可能有效,但不是保证的:
SELECT
u.fullname,
a.id,
a.content,
a.addDT,
a.`right`,
acr.score,
acr.checkDT
FROM
(answers a,
users u)
LEFT JOIN `answer_chk_results` acr ON acr.aid = a.id
WHERE
a.qid = 7
AND u.id = a.uid
GROUP BY
a.`right` DESC
关于mysql - MySQL Unknown列问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12326707/