I have two table in my SQL Database
One is Companies & Another is Company_advertisements.
I want to update field of company table “adv”
SET Company.adv = 1 if Company_adv.image is not empty
SET Company.adv = 0 if Company_adv.image is empty
The foreign key for Company_adv table is company_id
I tried using the following syntax but it didn’t worked.Instead after running this query all the values of Companmy.adv become 1 after that
I tried this query:
UPDATE companies cmp, company_adv cma
SET cmp.adv=1
WHERE cma.company_id=cmp.id AND
cma.image1 IS NOT NULL
Please help me !!
if that’s the case, you need to use
LEFT JOIN