sqlstreak

SQL error

syntax error at or near "FROM" / near "FROM": syntax error

Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)

Short answer

The parser hit something it didn't expect just before the word in the message. Look at what comes right before it: most often a trailing comma, a missing comma, an unclosed quote or a reserved word used as a name.

The exact messages

  • PostgreSQLERROR: syntax error at or near "FROM"
  • SQLitenear "FROM": syntax error

How to read this message

This is what PostgreSQL 18.6 prints for the broken query below, the way psql shows it. LINE gives the line it was reading when it gave up, and the ^ marks the exact spot.

ERROR:  syntax error at or near "FROM"
LINE 2: FROM pets;
        ^

SQLite 3.54.1 reports the same mistake as near "FROM": syntax error, with no line number: look for the word or column it names.

Why it happens

A trailing comma before FROM

SELECT name, age, FROM pets — the comma promises another column that never comes.

A reserved word as a column name

Columns called order, user or group must be quoted: "order". Better: rename them.

A missing comma

SELECT name age FROM pets reads as “name, renamed to age”, and the next error can appear far away.

An unclosed quote or parenthesis

Everything after it becomes part of the string, so the error points somewhere unexpected.

Reproduce it, then fix it

Both queries run on a real database in your browser. Switch dialects to compare.

Broken
SELECT name, age,
FROM pets;
Fixed
SELECT name, age
FROM pets;

Remove the comma after the last column. Many people put commas at the start of lines (, age) to make this mistake impossible.

The fix returns, PostgreSQL: first 6 of 20 rows

nameage
Biscuit3
Mochi2
Pickles7
Luna5
Waffles1
Bruno9

The fix returns, SQLite: first 6 of 20 rows

nameage
Biscuit3
Mochi2
Pickles7
Luna5
Waffles1
Bruno9

Experiment with it: PostgreSQL playground·SQLite playground

Official documentation

Stop hitting this error

Practise the concept behind it in a five-minute lesson, or read the full guide: The SQL SELECT statement.