Mysql – Error trying to SET a field when two fields in different tables match

MySQL

I am trying to set catid to 584 whenever the rows in the tables ykz2d_crmery_deals and ykz2d_maps_integration have the same company id using the following query:

UPDATE ykz2d_maps_integration 
SET catid = '584' 
WHERE ykz2d_crmery_deals.company_id = ykz2d_maps_integration.company_id

I keep getting the following error:

Failed to execute SQL : SQL UPDATE ykz2d_maps_integration SET catid = '584' WHERE ykz2d_crmery_deals.company_id = ykz2d_maps_integration.company_id failed : Unknown column 'ykz2d_crmery_deals.company_id' in 'where clause'

The column company_id does exist within ykz2d_crmery_deals.

What I can do to fix this?

Best Answer

UPDATE ykz2d_maps_integration , ykz2d_crmery_deals
SET catid = '584' 
where ykz2d_crmery_deals.company_id = ykz2d_maps_integration.company_id
;

The table must be listed in the update clause to avoi the error message