Error Reference › SQL / Database
SQL / Database
SQL syntax error (1064)
The database couldn't parse your SQL — there's a syntax mistake at the spot it names.
What it looks like
ERROR 1064 (42000): 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 'order BY id' at line 1
What does "SQL syntax error (1064)" mean?
Returned by MySQL when it cannot parse a statement. The part after “near” is where the parser gave up — the actual mistake is usually just before it, not inside the quoted text.
What causes "SQL syntax error (1064)"?
- A typo, missing comma, or unquoted value.
- A reserved word used as a column/table name unquoted.
- String concatenation that broke the query.
How do I confirm the cause?
- Look at the text immediately before the “near” fragment for a missing comma, bracket or quote.
- Check whether a table or column name is a reserved word (order, group, key, desc) that needs backticks.
- Print the final SQL your code sends, with values filled in — string-built queries often look fine in code and broken when run.
How do I fix "SQL syntax error (1064)"?
- Read the query around the position the error quotes.
- Quote reserved words (backticks in MySQL, double quotes in Postgres).
- Use parameterized queries instead of string-building.
How do I stop it happening again?
- Use prepared statements with placeholders instead of concatenating values into SQL.
- Avoid reserved words as table and column names.