DevTools Hub

Search tools

Search for a developer tool

Common SQL Syntax Errors

Part of the SQL Toolkit

The genuinely dangerous SQL mistakes aren't the ones that error — a parser rejecting your query is an annoyance, not a bug. The ones worth knowing well are the mistakes a database quietly accepts and runs anyway, just not the way you meant. Every example below was run against a real database rather than guessed at, including the syntax errors' exact wording and, more importantly, the handful of "errors" below that turned out not to error at all.

Trailing comma before a clause

SELECT id, name, FROM users;

The extra comma before FROM reads as a typo to a human and a syntax error to the database — verified: near "FROM": syntax error. Easy to introduce by adding a column and then removing it again, forgetting the trailing comma went with it.

Leading comma right after SELECT or (

SELECT , id, name FROM users;

Same category, opposite end — a comma with nothing before it to separate. Verified: near ",": syntax error. Common when reordering a column list and accidentally leaving the old separator in place.

Unbalanced parentheses

SELECT * FROM users WHERE id IN (1, 2, 3;

Worth knowing before you go looking: the error doesn't point at the missing ). Verified against this exact query, the real error lands on the ; at the end — near ";": syntax error — because that's where the parser finally gives up, not where the mistake actually is. On a long query, work backward from the reported line to the nearest unmatched paren rather than assuming the error location is the defect location.

Unterminated string literal

SELECT * FROM users WHERE name = 'Alice;

A missing closing quote doesn't just break the one value — everything after the open quote, including the semicolon, gets absorbed into the string until the parser finds a real or accidental closing quote (or runs out of input). Verified error: unrecognized token: "'Alice;" — note the semicolon is inside the reported token, swallowed along with the rest of the line.

A missing comma that doesn't error at all

SELECT id name FROM users;

This is the one worth actually worrying about. Forgetting the comma between id and name doesn't produce a syntax error — verified: it runs successfully, because column alias (no AS required) is itself valid syntax. name silently becomes the output column's alias for id, and the query returns only one column, not two, with no warning that anything is wrong. A missing comma between column names is one of the few SQL typos that changes behavior instead of failing loudly.

Double quotes where a string literal was meant

SELECT * FROM users WHERE name = "Alice";

Standard SQL reserves double quotes for identifiers (column and table names), not string values — single quotes are for strings. Verified: this query fails with no such column: Alice, not a syntax error, because "Alice" is parsed as a column reference, and there's no column by that name. The confusing part is the error message — it looks like a missing-column problem, not a quoting problem, unless you already know the rule.

MySQL is the exception worth flagging separately: by default (without ANSI_QUOTES mode enabled), MySQL treats double quotes exactly like single quotes — a string literal, not an identifier. The same query that fails on PostgreSQL or SQL Server can run fine on a default MySQL setup, which makes this a genuine cross-database portability trap, not just a style preference.

Single quotes where a column name was meant

SELECT 'id' FROM users;

The reverse mistake is worse, because it never errors. Verified against a real table with two rows: this returns the literal string id twice — once per row — not the values in the id column. 'id' is a string constant, and selecting a constant alongside a FROM clause just repeats it for every row matched. Nothing about the output looks obviously wrong unless you know what you expected.

An unquoted reserved word as an identifier

SELECT * FROM order;

ORDER is a SQL keyword (as in ORDER BY), so using it bare as a table name collides with the grammar. Verified: near "order": syntax error. Quoting it as an identifier — "order", `order`, or [order] depending on the database — resolves it, but the better fix is usually renaming the table; a table called orders (plural) sidesteps the entire class of reserved-word collisions.

Missing semicolon between statements

Whether this errors depends entirely on the client, not the SQL itself — some tools infer statement boundaries and run each one anyway, others report a confusing syntax error at the start of the second statement because they were still parsing the first one. Since the failure mode is client-dependent and inconsistent, it's worth terminating every statement explicitly rather than relying on a particular tool's leniency.

Unbalanced CASE / END

SELECT CASE WHEN id = 1 THEN 'a' ELSE 'b' FROM users;

Missing the closing END. Same lesson as the unbalanced-parens case: the reported error doesn't point at the missing keyword. Verified, the error lands on FROMnear "FROM": syntax error — because that's the token that finally didn't make sense to the parser, several words past where END should have been.

== instead of =

SELECT * FROM users WHERE id == 1;

Standard SQL defines exactly one equality operator, = — unlike C-family languages, there's no ==/= distinction between comparison and assignment to justify a double-equals. SQLite happens to accept == as a non-standard, documented extension, so this one can run for months in development against SQLite and then fail the moment the same query hits PostgreSQL, MySQL, or SQL Server — none of which recognize it.

Try it yourself

SQL Query Validator catches the structural mistakes above — unbalanced parens, stray commas, unterminated strings, unmatched CASE/END — with the correct quoting rules for PostgreSQL, MySQL, and SQL Server. It won't catch the silent ones (the missing comma that becomes an alias, the quote-type mix-up that returns wrong-but-valid results) since those aren't structural defects — nothing is wrong with the syntax, only with what it means. For those, reading the query back carefully is still the only real check. See also SQL Formatter for making a dense query easier to spot these in before running it at all.

Related tools