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
  • 51,770
  • 36
  • 127
  • 149
Yunus Eren Güzel
  • 3,018
  • 11
  • 36
  • 63
  • 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
  • 267,341
  • 46
  • 444
  • 390
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
  • 77,474
  • 47
  • 185
  • 261