Remember what I have answered earlier...
1. that you should use the subquery to validate that the correct items would be updated?
2. you need to do some more research on how
EXIST
works
These apply here as well...
Using this is just asking for trouble... IF for some reason this would work it will delete ALL entries in the
Take and
Loan tables IF there is a customer names 'Jones'.
WHERE Exists (
SELECT c.cust_name
FROM customer c
WHERE c.cust_id = t.cust_id
AND c.cust_name='Jones'
)
What you actually want to do is to select all of the loan numbers for that one customer...
What I would do is to relocate that JOIN into the subquery to find all of the Loan Numbers
SELECT t.Loan_Number
FROM Take t
INNER JOIN Customer c ON t.Cust_ID = c.CustID
WHERE c.cust_name='Jones'
And then use this as a subquery to delete all of the loans first...
DELETE Loan
WHERE Loan_Number IN (
)
This should have removed all of the Loan entries...
Now as a follow up, remove the entries from the Take table which was used to bridge the Customers to their Loans.
DELETE Take
WHERE Cust_ID IN (
SELECT Cust_ID
FROM Customer
WHERE Cust_Name='Jones'
)