MySQL: #1054 – Unknown column ‘table.columnname’ in ‘on clause’ Even Though Column Name Exists

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, October 30, 2008

Follow me on Twitter as @mattiasgeniar

You might run in to the following problem with a MySQL 5 installation.

SELECT *
FROM table1, table2
INNER JOIN table3 on table1.columnname = table3.columnname;

> #1054 – Unknown column ‘table1.columnname’ in ‘on clause’

While that would have been a valid query for previous MySQL versions, there is now a requirement to add round brackets around the tables you want to select through a “FROM”-clause.

Change the query to the following, and it will work again.

SELECT *
FROM (table1, table2)
INNER JOIN table3 on table1.columnname = table3.columnname;

You will most likely see this behaviour when upgrading from a MySQL4 to a MySQL5 environment, and it’s a b*tch to track this one down. The following bug reports were also made on MySQL, which might prove useful to you should the above not work.

  • Bug #1689: Unknown column in ‘field list’ for a field that does exist
  • Bug #13551: #1054 – Unknown column ‘xxxx’ in ‘on clause’
  • Bug #13597: Column in ON condition not resolved if references a table in nested right join


Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.