AI Hints
Home›SQL Tutorial›Reading Error Messages
SQL · Lesson 105 of 126

Syntax Errors

Commas and quotes.

⏱ 2 min read▶ Video at 2:28:49🎓 Free
Watch this lesson in the SQL courseWatch on YouTube ↗Full SQL course

A syntax error means SQL couldn't understand the grammar of your query. Usually it's something tiny. An extra comma, or a missing quote.

Syntax Errors
From the video: Syntax Errors
  • SQL couldn't understand it
  • Usually something tiny
  • Commas and quotes

The extra comma

There's a comma after title, but no column after it. Run it. Syntax error, near from. When the error says near a word, the real mistake is usually just before that word. Here, the extra comma.

query.sqlsql
SELECT title,
FROM books;
Output
Parse error near line 1: near "FROM": syntax error
  SELECT title, FROM books;
                ^--- error here

The missing quote

Here, the closing quote is missing. Run it. Unrecognized token. The text started with a quote, and never ended. Count your quotes. They always come in pairs.

query.sqlsql
SELECT title
FROM books
WHERE genre = 'Fantasy;
Output
Parse error near line 1: unrecognized token: "'Fantasy;"
  SELECT title FROM books WHERE genre = 'Fantasy;
                          error here ---^

A checklist for syntax errors

When you see a syntax error, check these four things. Commas between columns, but not after the last one. Quotes in pairs. Brackets in pairs. And keywords in the right order. Select, from, where, group by, having, order by, limit.

Commasbetween, not after the last
Quotesalways in pairs
Bracketsalways in pairs
OrderSELECT FROM WHERE ...

Summary

Syntax errors are about grammar. Look just before the word in the error message. Next, two errors that need a little more thought.

Key takeaways
  • near "X": look before X
  • Quotes in pairs
  • No comma after the last
Next up: Ambiguous and Misused — two thinking errors