Vidyalelo
SQL · Q40

SQL

Programming · SQL · question 40

Q40

Which of the following query finds the name of the sailors who have reserved at least two boats?

A.
SELECT DISTINCT s.sname FROM sailors s, reserves r1, reserves r2 WHERE s.sid = r1.sid AND r1.sid = r2.sid AND r1.bid ≠ r2.bid
B.
SELECT DISTINCT s.sname FROM sailors s, reserves r1, reserves r2 WHERE s.sid = r1.sid AND COUNT(r1.bid) > r2.bid
C.
SELECT DISTINCT s.sname FROM sailors s, reserves r1, reserves r2 WHERE s.sid = r1.sid AND r1.sid = r2.sid AND r1.bid <> r2.bid
D.
Both A and B
E.
Both A and C
Answer

Answer: Option E

Solution

Answer: Option E
Solution:
Both Option A and Option C can be used to find the name of sailors who have reserved at least two boats. They achieve this by joining the "sailors" and "reserves" tables twice, specifying that the sailor IDs (s.sid) should be the same in both reservations, and ensuring that the boat IDs (r1.bid and r2.bid) are different. This identifies sailors who have made multiple reservations. Therefore, the correct answer is Option E, which includes both A and C as valid choices for this query.