March 3, 2012
What am I missing in this SQL?
Question by exculuber
I’ve written some SQL for a MySQL database.
SELECT U.Id, U.Name, U.Surname
FROM match M
INNER JOIN created_by C
ON C.MatchId = M.Id
INNER JOIN user U
ON U.Id = C.UserId
WHERE M.Id = 3
I’m going crazy because it doesn’t seem wrong but the interpreter says there is a syntax error here near 'match M INNER JOIN created_by C ON C.MatchId=M.Id INNER JOIN user U O'.
Thanks for any advice.
Answer by Michael Berkowski
MATCH is a MySQL reserved keyword. Enclose it in backticks if you intend to use it as a column or table name.
SELECT U.Id, U.Name, U.Surname
FROM `match` M
Answer by Starx
I think user &match is an reserved keyword. You need to escape it. Try the following query
SELECT U.Id, U.Name, U.Surname
FROM `match` M
INNER JOIN `created_by` C
ON C.MatchId = M.Id
INNER JOIN `user` U
ON U.Id = C.UserId
WHERE M.Id = 3