Fix “Referenced Column Not Found” in SQL
No table in the FROM clause has a column by that name. Usually a typo or a table you did not join.
The symptom
The query names a column and the database answers Referenced column "prodct_price" not found in FROM clause. The statement parsed correctly, so the shape of the SQL is fine. The problem is that the name does not resolve to anything the query can see.
Why it happens
A column reference is resolved against the tables in theFROM clause, and nothing else. Three causes cover almost every case:
- The name is misspelled, as in the bench below.
- The column exists, but on a table you did not join, so it is not in scope.
- The column was renamed by an alias earlier in the query, and the old name no longer exists at this point.
The message names the column it could not resolve. Compare that string against the table's real column list before assuming the table is wrong.
The fix
Correct the spelling to price. If the name looks right, list the columns the table actually has and compare, usingdescribe products in DuckDB or the equivalent in your engine.
When the column belongs to another table, add the join that brings it into scope, then qualify the reference with the table alias so it is unambiguous.
A column referenced in ORDER BY is resolved after theSELECT list, so an output alias works there. The same alias inWHERE is not portable. Seefiltering on a SELECT alias.
How other engines word it
| Engine | Message |
|---|---|
| DuckDB | Binder Error: Referenced column "prodct_price" not found in FROM clause! |
| PostgreSQL | column "prodct_price" does not exist |
| MySQL | Unknown column 'prodct_price' in 'field list' (error 1054) |
| SQL Server | Invalid column name 'prodct_price'. |
| Oracle | ORA-00904: "PRODCT_PRICE": invalid identifier |
| SQLite | no such column: prodct_price |
Learn more
Related
Understand tables, rows, columns, and queries.
Learn the basic shape of relational data.
Run queries and read results in the browser.
Write a first SELECT and read the returned rows.