SQLSTATE 42P01 ERROR Class 42: Syntax Error or Access Rule Violation

undefined_table missing FROM-clause entry for table “…” — 42P01

PostgreSQL error "missing FROM-clause entry for table "…"" (SQLSTATE 42P01): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A query referenced a table/alias in a column reference that is not listed in the FROM clause. PostgreSQL raises SQLSTATE 42P01 (undefined_table).

  • A qualified column refers to a table not in FROM.
  • Common after renaming via an alias but using the original name.
  • Often a forgotten JOIN.

What the server log shows

ERROR:  missing FROM-clause entry for table "o"
LINE 1: SELECT o.id FROM orders ord;

Why PostgreSQL raises this — what the manual says

As Section 7.2.1 The FROM Clause explains:

Every table or alias used in a column qualification must appear in the query’s FROM clause; referencing a table name that is not listed there (or using the original name after assigning it an alias) leaves the reference unresolved.

Every table referenced in column qualifications must appear in the FROM clause (by name or alias). Referencing a name that isn’t there — e.g. using the real name after assigning an alias, or forgetting a JOIN — makes the reference unresolved, so PostgreSQL reports 42P01.

Common causes

  • Using the table’s original name after assigning it an alias.
  • Forgetting to add the table to FROM or a JOIN.
  • A typo in the table/alias qualifier.

How to fix it

  1. Reference the alias you defined (or remove the alias).
  2. Add the missing table to the FROM/JOIN clause.
  3. Correct the qualifier to match a table in scope.

Related & next steps

Reference: PostgreSQL 18 Section 7.2 “Table Expressions”.

Was this helpful?