Link to home
Start Free TrialLog in
Avatar of dkma2010
dkma2010

asked on

Convert Oracle SQL select statement to the proper Delete Statement

I'm trying to convert a select statement that is working correctly into a delete statement and I'm not having any luck. I'm trying to delete data from a parent and child table. The child table doesn't always have any child records but if it does then I want the data deleted in both tables if where clause is true. If there are no child records then I still want the parent table records to be deleted.
Here is the select statement that works like I want it to.
SELECT MY_PARENT.ID, MY_PARENT.PRINT_DATE, MY_CHILD_DTL.ID, MY_CHILD_DTL.MY_PARENT_ID
FROM MY_PARENT LEFT JOIN MY_CHILD_DTL ON MY_PARENT.ID = MY_CHILD_DTL.MY_PARENT_ID
WHERE MY_PARENT.PRINT_DATE IS NULL OR MY_PARENT.PRINT_DATE < (SYSDATE - 30)

I need to do the exact same thing with a DELETE COMMAND
ASKER CERTIFIED SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkma2010
dkma2010

ASKER

Thanks for the info found out that the cascading deletes were on so that took care of the problem. Appreciated the other code also.