2013-11-20 21 views
6

otrzymuję ten błąd: # 1054 - Unknown column 'examinationresults.userid' w 'o klauzuli'# 1054 - Unknown column in 'o klauzuli'

Widziałem inne posty na ten temat, ale mogę” Wydaje się, że to rozumiem. Nie sądzę, mam na myśli coś z rzędu ...

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; 

Odpowiedz

6

Masz

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

Nie mieszać ANSI 89 i ANSI 92 przyłączyć style.

Użyj także składni dla examinationresults i examination.

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' 
+0

Idealny. To ma dużo więcej sensu ... Naprawdę robiłam to samo na dwa różne sposoby, używając FROM/WHERE do przyłączenia się ... INNER JOIN (ANSI 92, jak zakładam?) Jest znacznie lepszy i bardziej przejrzysty. – Edward

+1

@Edward - Yes sprzężenie wewnętrzne to wersja ANSI 92. Jeśli zmiksujesz typy łączenia, skończysz z mieszaną mieszanką pierwszeństwa. Właśnie zauważyłem, że podczas szukania w Google problemu z priorytetem, jest to faktycznie duplikat. [Więcej wyjaśnienia w odpowiedzi tutaj] (http://stackoverflow.com/a/4065993/73226) –

2

zapomni użyć składni sprzężenia wewnętrznego dla examinationresults i examination .Try to:

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' 

Na marginesie:

Możesz sprawdzić

Bad habits to kick : using old-style JOINs

Aaron Bertrand na przykład.