AH. AH. - 3 months ago 4
MySQL Question

Unknown column in JOIN ON statement MySQL

SELECT * FROM `a` LEFT JOIN `dates` ON `a.date_id`=`dates.id` AND `dates.date`>'19-09-2013'


The above query gets
#1054 - Unknown column 'a.date_id' in 'on clause'

Answer

If you escape a table or column name you have to do it seperatly

SELECT * FROM a 
LEFT JOIN  `dates` ON a.date_id = `dates`.`id` AND `dates`.`date` > '19-09-2013'

Use

`dates`.`id`

instead of

`dates.id`

But you actually only have to escape reserved words in MySQL.

Comments