ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7 select S.*, D.Name, D.IsACupBoolean, D.DivisionID from Divisions D, Seasons S where S.SeasonID = D.SeasonID and D.DivisionID = ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and M.IsAnExhibition = 0 GROUP BY S.PlayerID order by 2 ' at line 19 SELECT S.PlayerID, count(*) Goals, max(FirstName) FirstName, max(LastName) LastName, (select max(TeamName) from Teams T, TeamRosters TR, Leagues L where TR.PlayerID = S.PlayerID and T.TeamID = TR.TeamID and TR.SeasonID = 2017 and TR.IsActive = 1 and L.TeamID = T.TeamID and L.DivisionID = M.DivisionID) TeamName, (select max(T.TeamID) from Teams T, TeamRosters TR, Leagues L where TR.PlayerID = S.PlayerID and T.TeamID = TR.TeamID and TR.SeasonID = 2017 and TR.IsActive = 1 and L.TeamID = T.TeamID and L.DivisionID = M.DivisionID) TeamID FROM Scorers S, Matches M, Players P WHERE M.MatchID = S.MatchID and P.PlayerID = S.PlayerID and M.DivisionID = and M.IsAnExhibition = 0 GROUP BY S.PlayerID order by 2 desc, 5, 4