Skip to content
Advertisement

Unknown column in field list when use join MySQL

I have 2 tables like this:

product_master:

campaign_product:

This tables link with foreign key product_id

I want to get all product data with campaign_code column. I don’t want to get 2 campaign_product row with same product_id. So I use this query:

It got error when I run:

Error in query (1054): Unknown column ‘dmspro_mys_campaign_product.campaign_code’ in ‘field list’

How I can fix this?

Thank you!

Advertisement

Answer

Column campaign_code is not returned by the subquery. Also, table alias dmspro_mys_campaign_product is not available in the outer query, only in the subquery.

You should modify the subquery so it returns it:

I also fixed your query to use table aliases for both tables: this shortens the query and makes it more readable.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement