I have two tables with following columns:
SUMMARY(sum_id, sum_number) and DETAILS(det_id, det_number, sum_id)
I want to delete rows from table DETAILS
with det_id in list of IDs, which can be done by:
DELETE FROM details WHERE det_id in (1,2,3...)
BUT
At the same time I need to update table
SUMMARY
ifsummary.sum_id=details.sum_id
UPDATE summary SET sum_number-=somefunction(details.det_number) WHERE summary.sum_id=details.sum_id
More over, afterwards it would be totally great to delete rows from
SUMMARY
table ifsum_number<=0
How to do all this in an intelligent way?
What if i know, from the very beginning, both IDs: details.det_id
(to delete) AND summary.sum_id
which correspond to details.det_id