0

Could someone please help me to find this error? It seems I have named some queries in a wrong place. I copy and paste: Error

SQL query: Documentation

SELECT `Schools`.`School Name` , `Studentlogin`.`School Code` ,   `Studentlogin`.`Group` , `NewResults`.`Test` , `NewResults`.`Question` , `NewResults`.`Blank` , `NewResults`.`A` , `NewResults`.`B` , `NewResults`.`C` , `NewResults`.`D` , `NewResults`.`E` , `NewResults`.`Correct` , `Schools`.`State` , `Schools`.`District` , `Run_Date` , `Studentlogin`.`AutoId` AS Ind1
FROM Schools
INNER JOIN Studentlogin ON `Studentlogin`.`School Code` = `Schools`.`School Code`
INNER JOIN NewResults AS T1 ON ( NewResults.Student = Studentlogin.AutoId )
INNER JOIN (

SELECT Max( `Run_Date` ) AS Maximus, Studentlogin.AutoId AS Ind2
FROM Schools
INNER JOIN Studentlogin AS T2 ON ( `Studentlogin`.`School Code` =`Schools`.`School Code` )
INNER JOIN NewResults ON ( NewResults.Student = Studentlogin.AutoId )
WHERE (
NewResults.Test = '27'
)
AND (
`Schools`.`School Code` = '9'
)
) ON ( T1.Ind1 = T2.Ind2
AND Run_Date = Maximus )
GROUP BY Studentlogin.AutoId, Question

MySQL said: Documentation

#1248 - Every derived table must have its own alias

  • Add alias in the subquery. – Maxi Schvindt Apr 19 '16 at 20:01
  • The subquery has it, may be in the wrong place : FROM Schools INNER JOIN Studentlogin AS T2 – Luis Madiedo Apr 19 '16 at 20:46
  • Neither in this place: SELECT Max( `Run_Date` ) as Maximus,Studentlogin.AutoId as Ind2 FROM Schools AS T2 ...... same error message. – Luis Madiedo Apr 19 '16 at 20:49
  • If I put in this way: SELECT Max( `Run_Date` ) as Maximus,Studentlogin.AutoId as Ind2 FROM Schools Inner Join Studentlogin on (`Studentlogin`.`School Code` = `Schools`.`School Code`) Inner Join NewResults on (NewResults.Student = Studentlogin.AutoId) where ( NewResults.Test = '27') AND (`Schools`.`School Code` = '9') ) AS T2 on (T1.Ind1=T2.Ind2 and Run_Date=Maximus) GROUP BY Studentlogin.AutoId,Question I receive another error message: MySQL said: Documentation #1054 - Unknown column 'NewResults.Test' in 'field list' – Luis Madiedo Apr 19 '16 at 20:54

0 Answers0