MySQL 8.4Lab-verified · 2026-11-29

MySQL ERROR 1054 (42S22): Unknown column

MySQL could not find a column with that name in the tables available at that point of the query.

MySQL 8.4.13
1054 (42S22): Unknown column 'username' in 'field list'

Jump to a cause

  1. 01The column name is misspelled
  2. 02A string value without quotes in WHERE
  3. 03Using a SELECT alias in WHERE
  4. 04Mixing comma joins with JOIN … ON

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4

The message names the column and the part of the query where it was used: 'field list' is the SELECT list (or the INSERT column list), 'where clause' is WHERE, 'on clause' is a JOIN condition. That second part narrows down the cause quickly.

The "column" is not always a column you meant to write. An unquoted string value, or an alias defined in the SELECT list, is also looked up as a column name.

01The column name is misspelled

The table has user_name, but the query asks for username. SHOW COLUMNS FROM users lists the real column names.

Setup
Setuprun as lab_a
CREATE TABLE users (id INT PRIMARY KEY, user_name VARCHAR(50), email VARCHAR(100));
INSERT INTO users VALUES (1, 'Kim', 'kim@example.com');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
SELECT id, username FROM users;
✕ ERROR
ERROR 1054 (42S22): Unknown column 'username' in 'field list'
Checkrun as lab_a
SHOW COLUMNS FROM users;
OUTPUT
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| id        | int          | NO   | PRI | NULL    |       |
| user_name | varchar(50)  | YES  |     | NULL    |       |
| email     | varchar(100) | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

Use the name exactly as SHOW COLUMNS shows it. Column names are not case-sensitive in MySQL, so the problem is the spelling, not the case.

After the fixrun as lab_a
SELECT id, user_name FROM users;
✓ SUCCESS
+----+-----------+
| id | user_name |
+----+-----------+
|  1 | Kim       |
+----+-----------+
1 row in set (0.00 sec)

02A string value without quotes in WHERE

WHERE user_name = Kim has no quotes, so MySQL reads Kim as a column name and reports Unknown column 'Kim' in 'where clause'. This often happens when SQL is built by concatenating a variable into the string.

Setup
Setuprun as lab_a
CREATE TABLE users (id INT PRIMARY KEY, user_name VARCHAR(50));
INSERT INTO users VALUES (1, 'Kim'), (2, 'Lee');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT id, user_name FROM users WHERE user_name = Kim;
✕ ERROR
ERROR 1054 (42S22): Unknown column 'Kim' in 'where clause'
Checkrun as lab_a
SELECT 'Kim' AS quoted_value;
OUTPUT
+--------------+
| quoted_value |
+--------------+
| Kim          |
+--------------+
1 row in set (0.00 sec)

Put string values in single quotes ('Kim'). In application code, use placeholders (prepared statements) instead of concatenating values; the driver then handles quoting.

After the fixrun as lab_a
SELECT id, user_name FROM users WHERE user_name = 'Kim';
✓ SUCCESS
+----+-----------+
| id | user_name |
+----+-----------+
|  1 | Kim       |
+----+-----------+
1 row in set (0.00 sec)

03Using a SELECT alias in WHERE

total is an alias created in the SELECT list. WHERE is evaluated before the SELECT list, so the alias does not exist yet and MySQL reports Unknown column 'total' in 'where clause'.

Setup
Setuprun as lab_a
CREATE TABLE order_lines (id INT PRIMARY KEY, price DECIMAL(10,2), qty INT);
INSERT INTO order_lines VALUES (1, 30.00, 2), (2, 50.00, 3), (3, 10.00, 1);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT id, price * qty AS total FROM order_lines WHERE total > 50;
✕ ERROR
ERROR 1054 (42S22): Unknown column 'total' in 'where clause'
Checkrun as lab_a
SELECT id, price * qty AS total FROM order_lines;
OUTPUT
+----+--------+
| id | total  |
+----+--------+
|  1 |  60.00 |
|  2 | 150.00 |
|  3 |  10.00 |
+----+--------+
3 rows in set (0.00 sec)

Repeat the expression in WHERE (price * qty > 50). This returned ids 1 and 2.

After the fixrun as lab_a
SELECT id, price * qty AS total FROM order_lines WHERE price * qty > 50;
✓ SUCCESS
+----+--------+
| id | total  |
+----+--------+
|  1 |  60.00 |
|  2 | 150.00 |
+----+--------+
2 rows in set (0.00 sec)

04Mixing comma joins with JOIN … ON

In FROM customers c, orders o JOIN items i ON …, JOIN binds tighter than the comma. The ON clause belongs to orders o JOIN items i only, so c.id is not visible there and MySQL reports Unknown column 'c.id' in 'on clause'. This is a classic error in queries written for older MySQL versions.

Setup
Setuprun as lab_a
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, item_id INT);
CREATE TABLE items (id INT PRIMARY KEY, title VARCHAR(50));
INSERT INTO customers VALUES (1, 'Kim');
INSERT INTO items VALUES (10, 'pen');
INSERT INTO orders VALUES (100, 1, 10);
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.02 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
SELECT c.name, i.title
FROM customers c, orders o
JOIN items i ON i.id = o.item_id AND o.customer_id = c.id;
✕ ERROR
ERROR 1054 (42S22): Unknown column 'c.id' in 'on clause'
Checkrun as lab_a
SELECT c.name, o.id AS order_id FROM customers c, orders o WHERE o.customer_id = c.id;
OUTPUT
+------+----------+
| name | order_id |
+------+----------+
| Kim  |      100 |
+------+----------+
1 row in set (0.00 sec)

Write every join as an explicit JOIN … ON. The rewritten query returned Kim and pen.

After the fixrun as lab_a
SELECT c.name, i.title
FROM customers c
JOIN orders o ON o.customer_id = c.id
JOIN items i ON i.id = o.item_id;
✓ SUCCESS
+------+-------+
| name | title |
+------+-------+
| Kim  | pen   |
+------+-------+
1 row in set (0.00 sec)

FAQ

How do I fix MySQL error 1054 Unknown column in 'field list'?

Compare the column name in the message with SHOW COLUMNS FROM table. In an INSERT, the same message appears when the column list has a name the table does not have.

Why does MySQL say Unknown column for a string value?

The value has no quotes, so it is read as a column name. Write 'Kim' with single quotes, or use placeholders in your application code.

Can I use a column alias in WHERE in MySQL?

No. WHERE is evaluated before the SELECT list, so the alias is unknown there. Repeat the expression in WHERE.

What does Unknown column in 'on clause' mean?

The column belongs to a table that is not visible in that ON clause, most often because comma joins and JOIN … ON are mixed. Rewrite every join as an explicit JOIN.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13