sqlstreak

SQL error

invalid reference to FROM-clause entry for table "customers"

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

Short answer

Once a table has an alias in FROM, the query must use the alias: after FROM customers c, write c.name, not customers.name. The table's own name is hidden by the alias.

The exact messages

  • PostgreSQLERROR: invalid reference to FROM-clause entry for table "customers"
  • SQLiteno such column: customers.name

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. HINT is PostgreSQL's own suggestion, and it's usually worth following.

ERROR:  invalid reference to FROM-clause entry for table "customers"
LINE 1: SELECT customers.name, o.ordered_on
               ^
HINT:  Perhaps you meant to reference the table alias "c".

SQLite 3.54.1 reports the same mistake as no such column: customers.name, with no line number: look for the word or column it names.

Why it happens

Mixing the table name and its alias

Common after adding aliases to a query that used full table names. Replace every customers. with c..

A copied column list

Columns pasted from another query that used a different alias. PostgreSQL's hint names the alias it expected.

Reproduce it, then fix it

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

Broken
SELECT customers.name, o.ordered_on
FROM customers c
JOIN orders o ON o.customer_id = c.id;
Fixed
SELECT c.name, o.ordered_on
FROM customers c
JOIN orders o ON o.customer_id = c.id;

c is the only name customers has in this query.

The fix returns, PostgreSQL: first 6 of 17 rows

nameordered_on
Maya Ortiz2026-03-01
Jonah Reed2026-03-01
Maya Ortiz2026-03-03
Priya Nair2026-03-04
Tomás Herrera2026-03-05
Ellie Park2026-03-05

The fix returns, SQLite: first 6 of 17 rows

nameordered_on
Maya Ortiz2026-03-01
Jonah Reed2026-03-01
Maya Ortiz2026-03-03
Priya Nair2026-03-04
Tomás Herrera2026-03-05
Ellie Park2026-03-05

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: SQL JOINs explained.