I write “Find sids who made exactly one reservation”query with Using group by having like this:
SELECT R.sid
FROM Sailors S,
Reserve R
WHERE R.sid = S.sid
GROUP BY R.sid
HAVING Count(R.sid) = 1
But I want to alsa find it by using (not exists) command.I write it
SELECT S.sid
FROM Sailors S
WHERE NOT EXISTS (SELECT R.sid
FROM Reserve R
WHERE Count(R.sid) <> 1)
But it has errors.How can I write it by using not exists command.
If Reserve has a primary key rid, you can write it like so:
Note, in this case you don’t even need to reference the Sailors table:
http://sqlfiddle.com/#!3/cce6c/2