#1054 - 'on子句'中的未知列

时间:2013-11-20 20:44:19

标签: mysql sql join

我收到此错误:

  

#1054 - 'on clause'

中的未知栏'examineresults.userid'

我已经看过其他帖子,但我似乎无法弄明白。我不认为我指的是任何乱序......

SELECT examinationresults.id AS id, examinationresults.examid AS examid, 
examination.tag AS examtag, examination.title AS examtitle, examinationresults.revision AS revision, 
examination.medicalspecialtyid AS medicalspecialtyid, medicalspecialties.title AS medicalspecialtytitle, 
examination.institutionid AS institutionid, institutions.title AS institutiontitle, 
examinationresults.grade AS grade, examinationresults.points AS points, examinationresults.pointsof AS pointsof, 
examinationresults.datebegan AS datebegan, examinationresults.datefinished AS datefinished, 
examinationresults.totaltime AS totaltime, examinationresults.finished AS finished, examinationresults.graded AS graded, 
users.username AS username, users.firstname AS firstname, users.middlename AS middlename, users.lastname AS lastname 
FROM examinationresults, examination 
INNER JOIN medicalspecialties 
    ON examination.medicalspecialtyid=medicalspecialties.id 
INNER JOIN institutions 
    ON examination.institutionid=institutions.id 
INNER JOIN users 
    ON examinationresults.userid=users.id 
WHERE examination.examid=examinationresults.examid AND examination.revision=examinationresults.revision AND examinationresults.userid='1' 
ORDER BY examinationresults.datefinished ASC;

2 个答案:

答案 0 :(得分:7)

你有

FROM examinationresults, examination 
INNER JOIN medicalspecialties /*....*/

不要混用ANSI 89和ANSI 92连接样式。

使用INNER JOINexaminationresults的{​​{1}}语法。

examination

答案 1 :(得分:2)

您忘记使用examinationresultsexamination的INNER JOIN语法。试试这个:

SELECT examinationresults.id AS id, examinationresults.examid AS examid, 
examination.tag AS examtag, examination.title AS examtitle, examinationresults.revision AS revision, 
examination.medicalspecialtyid AS medicalspecialtyid, medicalspecialties.title AS medicalspecialtytitle, 
examination.institutionid AS institutionid, institutions.title AS institutiontitle, 
examinationresults.grade AS grade, examinationresults.points AS points, examinationresults.pointsof AS pointsof, 
examinationresults.datebegan AS datebegan, examinationresults.datefinished AS datefinished, 
examinationresults.totaltime AS totaltime, examinationresults.finished AS finished, examinationresults.graded AS graded, 
users.username AS username, users.firstname AS firstname, users.middlename AS middlename, users.lastname AS lastname 

FROM   examinationresults
       INNER JOIN examination
         ON examination.examid = examinationresults.examid
            AND examination.revision = examinationresults.revision
       INNER JOIN medicalspecialties
         ON examination.medicalspecialtyid = medicalspecialties.id
       INNER JOIN institutions
         ON examination.institutionid = institutions.id
       INNER JOIN users
         ON examinationresults.userid = users.id
WHERE  examinationresults.userid = '1'

旁注:

您可以查看Aaron Bertrand的

Bad habits to kick : using old-style JOINs

作为参考。