I have a databases test tomorrow and am hoping someone can confirm this answer for me. Say I have a schema of this:
branch (branch_name, branch_city, assets)
customer (customer_name, customer_street, customer_city)
account (account_number, branch_name, balance)
loan (loan_number, branch_name, amount)
depositor (customer_name, account_number)
borrower (customer_name, loan_number)
The question I am curious about is:
“Find the names of all customers who have a loan of more than £5000 but no account with a balance of more than £500.”
Original code:
π customer_name
(σ amount > 5,000 ^ balance < 500
(borrower ⋈ loan ⋈ depositor ⋈ account))
Edit: Having looked at Erwin Smout’s advice, I’ve amended my code to the following:
π customer_name
(σ amount > 5,000 (borrower ⋈ loan))
-
π customer_name
(σ balance < 500 (depositor ⋈ account))
Is that correct?
I’ll just answer my own question as I now know it is correct. Thanks to everyone who helped: