Suppose, I have a product table. It has product_id and product_name columns. and I've a table product_purchase
pr_pur_id product_id(FK) pur_quantity
1 170 6
2 190 6
3 270 0
4 70 1
5 10 6
6 20 6
and I've a product_sale table. The Table has pr_sale_id , product_id(FK) and sale_quantity columns.
If I want to insert product_sale which product_id has already in product_purchase table, the product_purchase.pr_pur_id should delete if product_purchase.pur_quantity is 0. If the product_purchase.pur_quantity is more then 0 it will reduce depends on product_sale.sale_quanity.
How can I execute update or delete query depends on product_purchase.pur_quantity column?