Vidyalelo
SQL · Q38

SQL

Programming · SQL · question 38

Q38

Which of the following query finds colors of boats reserved by "Dustin"?

A.
SELECT DISTINCT b.color FROM boats b, sailors s WHERE s.sname = 'Dustin' AND s.sid = b.sid
B.
SELECT DISTINCT b.color FROM boats b, reserves r, sailors s WHERE s.sname = 'Dustin' AND s.sid = r.sid AND r.bid = b.bid;
Answer
C.
SELECT DISTINCT b.color FROM boats b, reserves r, sailors s WHERE s.sname = 'Dustin' AND s.sid = r.sid
D.
SELECT DISTINCT b.color FROM boats b, reserves r, sailors s WHERE s.sname = 'Dustin' AND r.bid = b.bid

Answer: Option B

Solution

Answer: Option B
Solution:
To find the colors of boats reserved by "Dustin," you should use the SQL query SELECT DISTINCT b.color FROM boats b, reserves r, sailors s WHERE s.sname = 'Dustin' AND s.sid = r.sid AND r.bid = b.bid; (Option B). This query joins the "boats," "reserves," and "sailors" tables to find the colors of boats reserved by "Dustin." It ensures that the sailor's name is "Dustin" (s.sname = 'Dustin') and matches the sailor's ID to the reservation's sailor ID (s.sid = r.sid) and the reservation's boat ID to the boat's ID (r.bid = b.bid). The use of DISTINCT ensures you get unique boat colors. Option B is the correct choice for obtaining this information.