MySQL – Fixing ‘Unknown Column’ Query Error

MySQL

I get error (1054): Unknown column 'wp_jpnx_survey_code.supplier_id' in 'field list'
But that column does exist… Does anyone know why or how to fix this?

This is the code I used:

CREATE VIEW survey_codes_complete_overview AS SELECT *,
wp_jpnx_survey_code.supplier_id AS a_id,
wp_jpnx_survey_supplier_info.supplier_id AS b_id FROM
wp_jpnx_survey_code AS a LEFT JOIN wp_jpnx_survey_supplier_info AS b
ON a.supplier_id = b.supplier_id;

Best Answer

You are using aliases for those tables. So, specify the alias when selecting the column.

CREATE VIEW survey_codes_complete_overview AS 
SELECT *, 
a.supplier_id AS a_id, 
b.supplier_id AS b_id 
FROM wp_jpnx_survey_code AS a 
LEFT JOIN wp_jpnx_survey_supplier_info AS b 
ON a.supplier_id = b.supplier_id
Related Question