I am reading a textbook and I do not understand this query: Find sailors who’ve reserved all boats.
- We have 3 tables:
- Sailors: sid, sname, rating, age (primary: sid)
- Boats: bid (primary: bid)
- Reserves: sid, bid, day (primary, sid, bid, day) (sid is foreign key to sailors, bid is foreign key to boats)
For the query, Find sailors who’ve reserved all boats, the answer given is:
SELECT S.sname
FROM Sailors S
WHERE NOT EXISTS
((SELECT B.bid
FROM Boats B)
EXCEPT
(SELECT R.bid
FROM Reserves R
WHERE R.sid=S.sid))
My questions are:
Is there something wrong with the above query? When I put it into MySQL Workbench, it shows I have syntax error with the EXCEPT
Beside the solution given by the book above, is there any other way to do the query: Find sailors who’ve reserved all boats
Thank you,