Home > Net >  Can't figure out this syntax error in SQL SELECT statement
Can't figure out this syntax error in SQL SELECT statement

Time:05-01

I have been trying to get a simple SELECT statement to work but I keep getting a syntax error on the LEFT JOIN. The code:

SELECT
p.player_name,
s.country_name
FROM player_mast p
WHERE p.team_id=1217
LEFT JOIN soccer_country s ON p.team_id = s.country_id;

Seems pretty simple i guess, but it keeps giving me this error:

Error Code: 1064. 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 'LEFT JOIN soccer_country AS s ON p.team_id = s.country_id' at line 6

I'm using MySQL 8.0 and I have checked the documentation. I am a beginner with SQL so I'm sure I'm missing something obvious, but I just can't figure out what..

Help is much appreciated.

CodePudding user response:

JOIN clause should come before the WHERE clause.

SELECT
p.player_name,
s.country_name
FROM player_mast p
LEFT JOIN soccer_country s ON p.team_id = s.country_id
WHERE p.team_id=1217;
  • Related