Nested Queries
Powerful feature of SQL: WHERE clause can itself contain an SQL query!
- Actually, so can FROM and HAVING clauses.
To find sailors who’ve not reserved #103, use NOT IN.
To understand semantics of nested queries:
- think of a nested loops evaluation: For each Sailors tuple, check the qualification by computing the subquery.
WHERE S.sid IN (SELECT R.sid
Names of sailors who’ve reserved boat #103: