Oracle sql not exists deletes all my records -
i have following tables
product product_id parent_product_id product_details product_id percent and parent tables:
parent_product parent_product_id description_1 parent_product_details parent_product_id percent what need logic delete product_detail not exists(..the data parent_product_detail)
and
insert product_detail not exists (data parent_product_details)
when execute
delete product_details pd not exists (select ppd.* parent_product pp, parent_product pd, product p, parent_product_details ppd, ,product_details pd pp.parent_product_id = '172' , pd.parent_product_id = ppd.parent_product_id , ppd.parent_product_id = pp.parent_product_id , pd.product_id = p.product_id -- filter ) / rollback / 1040 rows deleted roll completed the problem have product doesn't have product details. when the subquery selected / execute shows 1 result
select ppd.* parent_product pp, parent_product pd, product p, parent_product_details ppd, --,product_details pd pp.parent_product_id = '172' , pd.parent_product_id = ppd.parent_product_id , ppd.parent_product_id = pp.parent_product_id --and pd.product_id = p.product_id -- filter how go deleting product_details records no longer present in parent_product_details , add new ones insert not exists logic?
i think want correlated subquery. need fix syntax use proper join syntax, not archaic commas-in-the-from-clause thing:
delete product_details pd not exists (select 1 parent_product pp join parent_product_details ppd on ppd.parent_product_id = pp.parent_product_id join parent_product mc on mc.parent_product_id = ppd.component_parent_product_id product p on p.parent_product_id = pp.parent_product_id pp.parent_product_id = '172' , pd.product_id = p.product_id -- filter );
Comments
Post a Comment