MySQL & MariaDB error 1054: Unknown column
Unknown column 'SQL_CACHE' in 'field list' (8.0.46) The statement refers to a column the server can't find in the tables it is reading. Often a typo, a column alias used too early, or a quoted string the server reads as a column name.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_BAD_FIELD_ERROR | ER_BAD_FIELD_ERROR |
| SQLSTATE | 42S22 | 42S22 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
The message names the column and the part of the statement it appeared in: Unknown column 'full_name' in 'field list', … in 'where clause', … in 'on clause'. The second part is the quickest clue to where to look.
Why it happens
- A typo, or the column was renamed or dropped.
- An alias used in WHERE:
SELECT price * qty AS total … WHERE total > 100. WHERE is evaluated before the SELECT list, so the alias doesn’t exist yet. (HAVING and ORDER BY can use it.) - Double quotes: with
ANSI_QUOTESinsql_mode(and in some tools),"Ann"means an identifier, not a string, soWHERE name = "Ann"looks for a column called Ann. Use single quotes for strings. - In a JOIN with
USINGor a comma join mixed withJOIN, a table isn’t visible in theONclause where you reference it. - In a trigger,
NEW.colorOLD.colnames a column the table doesn’t have. Our tests found exactly this bug in an old audit-trigger guide. SELECT … SQL_CACHEon MySQL 8.0 also gives 1054, because the query cache keywords were removed.
How to fix it
DESCRIBE tablename;and compare the spelling and case.- Repeat the expression instead of the alias in WHERE, or move the condition to HAVING, or wrap the query in a derived table.
- Use single quotes for string values, backticks for identifiers.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE emp (id INT, name VARCHAR(20));Run:
SELECT id, full_name FROM emp;
You get: Unknown column 'full_name' in 'SELECT'(11.8.9)
Verified fixes
Repeat the expression in WHERE (or use HAVING / a derived table)
SELECT id * 2 AS dbl FROM emp WHERE id * 2 > 2;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Reference a column the table doesn't have repro | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 |
| A string in double quotes under ANSI_QUOTES is read as a column name version check | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 |
| A SELECT alias used in WHERE version check | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 | ✓ 1054 |
| Repeat the expression in WHERE (or use HAVING / a derived table) fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Related errors
Where this error shows up in our guides
- Query_cache_type · SELECT SQL_CACHE ... (original) MySQL 8.0 8.4 9
- Resetting lost root password · --skip-grant-tables + UPDATE mysql.user SET password=PASSWORD() (pre-5.7 recipe) MySQL 5.7
- Runtime values · Post's trigger (NEW.WITHDRAWL typo) then INSERT MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Triggers for auditing · Post's audit table + triggers, then INSERT (original as published) MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Triggers for auditing · Post's UPDATE trigger references NEW.QUANTITY (not in table) MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8