delete from product_categories where category IN (select distinct category from product_categories PC LEFT JOIN categories C on PC.category = C.code WHERE code is NULL);

MySQL example:


delete PC from product_categories PC left join products P on PC.sku = P.sku where P.sku is NULL;

delete C from categories C left join product_categories PC on C.code = PC.category where C.parent > 0 and PC.category is NULL;

MySQL example for multiple table update:

update categories C left join product_categories PC on PC.category = C.code set count = count + 1 where PC.sku = 'ACN4551';