0

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.

Ben
  • 50,172
  • 36
  • 122
  • 141
Yunus Eren Güzel
  • 2,808
  • 9
  • 35
  • 62
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – Ian Ringrose May 06 '14 at 10:12

2 Answers2

8

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 
Michael Berkowski
  • 260,803
  • 45
  • 432
  • 377
3

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
Starx
  • 75,098
  • 44
  • 181
  • 258