I wrote a “Find sids who made exactly one reservation” query with a GROUP BY and HAVING clause 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 also find it by using unique command. My friend asked me but I can’t solve it. We don’t use group by. We solve it with unique. I tried but i can’t solve it. Can you help me?
SELECT UNIQUEdoesn’t do what you want. In Oracle it’s the same asSELECT DISTINCT. It doesn’t find the unique rows. It removes the duplicates.You have to use
GROUP BY ... HAVING ....