在實際狀況中,有供應商supplier表,而供應商對應商品表(t_pd_product),商品對應價格(t_pd_specification),商品對應圖片表(t_pd_picture)等等。
假設我讓你刪除供應商ID爲23的商品信息,價格信息,圖片信息,你該如何操做??sql
-- 刪除某個供應商對應的商品圖片code
DELETE FROM t_pd_picture WHERE id IN ( SELECT ID FROM ( SELECT id FROM t_pd_picture pic WHERE EXISTS ( SELECT 1 FROM t_pd_product t WHERE t.supplier_id = 23 AND pic.product_id = t.id )) template );
-- 刪除某個供應商的價格圖片
DELETE FROM t_pd_specification WHERE id IN ( SELECT ID FROM ( SELECT id FROM t_pd_specification spec WHERE EXISTS ( SELECT 1 FROM t_pd_product t WHERE t.supplier_id = 23 AND spec.product_id = t.id )) template );
-- 刪除某個供應商的商品ci
delete from t_pd_product WHERE supplier_id = 23;