Smart SQL Tools for Every Database

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

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

Related fixes

Back to Top 10 SQL Errors