delete from MySQL with outer join

Here is the code to delete records from a MySQL table with an outer join.

e.g. to delete the records from a products_to_categories table that have no product in the products table:

delete from pc
using products_to_categories as pc
left outer join products p on pc.products_id =p.products_id
where isnull(p.products_id)

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.