Decoding “syntax error near …”

The token after "near" is where the parser gave up — the actual mistake is usually just BEFORE it. Reproduce yours below and get the parse error from a real engine, with DuckDB adding line/column positions.

press RUN (or Ctrl+Enter) — everything executes in your browser, nothing is uploaded

Reading the message

SQLite reports near "X": syntax error where X is the first token that could not continue a valid statement. A trailing comma before FROM yields near "FROM"; a missing comma between columns yields an error near the second column name. Read one token to the left of "near" and you've usually found it.

Frequent causes, in observed order

Trailing commas in the SELECT list or before a closing parenthesis. Reserved words as namesSELECT * FROM order fails because ORDER is a keyword; quote it ("order") or rename the table. Misplaced clauses — WHERE after GROUP BY, or LIMIT before ORDER BY. Engine-specific syntaxSELECT TOP 10 is SQL Server; SQLite/DuckDB/Postgres/MySQL all use LIMIT. Unbalanced quotes or parentheses, which push the error far from the real location — when "near" points at the very end of the statement, look for an unclosed quote.

Why test on two engines

DuckDB's parser reports the line and column and often suggests alternatives, while SQLite's message is terse. Running the same query on both engines (one click above) frequently disambiguates a confusing error. Both engines here are the real thing, so what parses here parses in production SQLite/DuckDB.

FAQ

What does the quoted token in the error mean?

It is the first token the parser could not fit into a valid statement — the mistake is usually immediately before it, not the token itself.

Why is the error at the end of my query?

An unclosed string quote or parenthesis makes the parser consume the rest of the statement, so it fails at the end. Balance quotes/parens first.

My table is named "order" and every query fails. Why?

ORDER is a reserved word. Quote the identifier ("order") or rename the table — renaming is kinder to everyone downstream.

Related: Fixing "no such column" · Validate a SQL query against your schema · Run SQL online (SQLite)