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
SUMMARYifsummary.sum_id=details.sum_idUPDATE summary SET sum_number-=somefunction(details.det_number) WHERE summary.sum_id=details.sum_idMore over, afterwards it would be totally great to delete rows from
SUMMARYtable 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