Top 10 SQL Errors
How to Fix MySQL "Unknown column"
MySQL cannot find the column in the table or query scope.
Example error message
ERROR 1054 (42S22): Unknown column 'username' in 'field list'
Common causes
- The column name is misspelled.
- The column does not exist in that table.
- You used an alias in the wrong part of the query.
- The query needs a JOIN.
Quick fix
SELECT name FROM users;
Find the missing column quickly
Verify the real column names before editing your query. This catches typos, wrong table aliases, and migration mismatches.
SHOW COLUMNS FROM users;
SELECT column_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'users';
Broken query vs fixed query
-- Broken: column does not exist in users
SELECT username FROM users;
-- Fixed: actual column is name
SELECT name FROM users;
Alias scope gotcha
-- Broken: alias u is referenced but users table is not aliased
SELECT u.name FROM users;
-- Fixed
SELECT u.name FROM users AS u;
JOIN gotcha
-- Broken: profile.email is referenced without joining profile
SELECT users.id, profile.email
FROM users;
-- Fixed
SELECT users.id, profile.email
FROM users
JOIN profile ON profile.user_id = users.id;
Checklist
- Check spelling of table and column names.
- Check the correct database, schema, and table alias.
- Compare your SQL dialect: MySQL, PostgreSQL, SQL Server, Oracle, or SQLite.
- Run a very small SELECT query first, then add conditions step by step.