I want to find the borrowers who took all loan types.
Schema:
loan (number (PKEY), type, min_rating)
borrower (cust (PKEY), no (PKEY))
Sample tables:
number | type | min_rating
------------------------------
L1 | student | 500
L2 | car | 550
L3 | house | 500
L4 | car | 700
L5 | car | 900
cust | no
-----------
Jim | L2
Tom | L1
Tom | L2
Tom | L3
Tom | L4
Tom | L5
Bob | L3
The answer here would be "Tom".
I can simply count the total number of loans and compare the borrower's number of loans to that, but I'm NOT allowed to (this is a homework exercise), for the purposes of this homework and learning.
I wanted to use double-negation where I first find the borrowers who didn't take all the loans and find borrowers who are not in that set. I want to use nesting with NOT EXISTS
where I first find the borrowers that didn't take all the loans but I haven't been able to create a working query for that.
NOT EXISTS
. – LangmuirSELECT b.cust FROM borrower b, loan l WHERE l.no = b.number AND NOT EXISTS (SELECT * FROM loan)
and this is incorrect so I was wondering where I should fix it. – ValiseNOT EXISTS
– Valise