SELECT s.season_id FROM tbl_season AS s, tbl_season_group AS sg, tbl_group_team AS gt WHERE s.season_id = sg.season_id AND sg.season_id = gt.season_id AND sg.group_id = gt.group_id AND gt.team_id = AND sg.playoff = 0 ORDER BY s.season_order DESC LIMIT 1 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 sg.playoff = 0 ORDER BY s.season_order DESC LIMIT 1' at line 9