I have three tables:
sailor
(sname, rating);boat
(bname, color, rating);reservation
(sname, bname, weekday, start, finish);
In order to get a list of sailors who have reserved every red boat, I have:
select s.sname from sailor s
where not exists(
select * from boat b
where b.color = 'red'
and not exists (
select * from reservation r
where r.bname = b.bname
and r.sname = s.sname));
I now need to rewrite this query with NOT IN instead of NOT EXISTS. Here's what I have so far:
select s.sname from sailor s
where s.sname not in (select s2.sname from sailor s2 where
s2.sname not in (select r.sname from reservation r where r.bname not in (
select b.bname from boat b where b.color <> 'red' )));
This, however, returns a list of all sailors who have reserved a red boat (not necessarily all of them). I'm having great difficulty checking whether or not a name in the list has reserved EVERY boat (I also cannot use COUNT()).
Any help is appreciated