[Fix] MySQL ERROR 1054 (42S22): Unknown Column

[Fix] MySQL ERROR 1054 (42522)- Unknown Column

The MySQL Error 1054 occurs when you try to reference a column that does not exist for a table and you run a SELECT, INSERT, UPDATE, or DELETE query on it.

Let's see by an example, say we have created a table called employee with the below columns,

Table: employee
employee_id employee_name employee_dob employee_dept employee_salary
101 Sam Wise 23/01/1980 Pharma $50,000
201 Diana West 23/01/2001 Finance $70,000


Select Statement:

    mysql> Select employee_age from employee;
    
    ERROR 1054 (42S22): Unknown column 'employee_age' in 'field list'

Update Statement:

    mysql> Update table employee set employee_age=20 where employee_id=101;
    
    ERROR 1054 (42S22): Unknown column 'employee_id' in 'where clause'

Insert Statement:

    mysql> insert into employee (employee_id,employee_name,employee_age) values (303,"Mike J",30);
    
    ERROR 1054 (42S22): Unknown column 'employee_id' in 'field list'

Delete Statement:

    mysql>delete from employee where employee_age=30;
    ERROR 1054 (42S22): Unknown column 'employee_age' in 'where clause'

As you can see the table does not have employee_age hence these errors.



Fix: MySQL ERROR 1054 (42S22)

  • Check if the column exists in the table.
  • Check that you have connected to the correct database schema (maybe you want UAT and connected to Staging)
  • If you have misspelled the column name, just provide the right one.
  • Make sure you are using the right table.
  • Nothing works, you may have to alter the table to incorporate the column if you really need it.
  • Comments & Discussion

    Facing issues? Have questions? Post them here! We're happy to help!