SQL Subquery Operator

What
SQL set operators allow the user to perform queries between and against sets.

IN/NOT IN
These set operators check if a certain element is in/not in a relation respectively. SELECT s.sname FROM Sailors s WHERE s.id IN (SELECT r.sid               FROM Reserves r                WHERE r.bid = 103)

EXISTS/NOT EXISTS
These set operators check if a set is empty/not empty respectively SELECT s.name FROM Sailors s WHERE EXISTS (SELECT *              FROM Reserves r               WHERE s.id = r.sid AND r.bid = 103) This query does the same exact thing as the query above.

ANY
This set operator can compare a tuple against the elements in a set SELECT s.sname FROM Sailors s WHERE s.rating > ANY (SELECT s1.rating                      FROM Sailors s1                       WHERE s1.sname = 'Horatio') This query selects the name of the sailors who have a higher rating than any other sailor named Horatio.

ALL
This set operator can compare a tuple against the elements in a set SELECT s.sname FROM Sailors s WHERE s.rating > ALL (SELECT s1.rating                      FROM Sailors s1                       WHERE s1.sname = 'Horatio') This query selects the name of the sailors who have a higher rating than all other sailors named Horatio