Andy Garcia Andy Garcia - 4 months ago 24
MySQL Question

Error 1248 (42000): Every derived table must have its own alias

How come I keep the Error 1248 (42000): Every derived table must have its own alias? I've given each table it's own alias haven't I? Sorry I'm not too sure what I'm doing wrong here since I'm in my first semester for MySQL.

SELECT p.PlayerAlias as "Player",
s.HiScore as "Score"
FROM Player as p INNER JOIN Score as s ON p.PlayerID = s.PlayerID
LEFT OUTER JOIN (
SELECT g.GameID
FROM Game as g
WHERE g.GameName = "Reaper"
) ON s.GameID = g.GameID
WHERE s.HiScore < 7000 AND s.HiScore > 4000;

Answer

you are missing an alias on the inner query right after the LEFT OUTER JOIN

SELECT p.PlayerAlias as "Player", 
       s.HiScore as "Score" 
  FROM Player as p INNER JOIN Score as s ON p.PlayerID = s.PlayerID 
       LEFT OUTER JOIN (
           SELECT g.GameID 
             FROM Game as g 
            WHERE g.GameName = "Reaper"
       ) as g ON s.GameID = g.GameID 
 WHERE s.HiScore < 7000 AND s.HiScore > 4000;