Consider the following three SQL queries (Assume the data in the people…
2015
Consider the following three SQL queries (Assume the data in the people table):
(a) Select Name from people where Age>21;
(b) Select Name from people where Height>180;
(c) Select Name from people where (Age>21) or (Height>180);
If the SQL queries 𝑎 and 𝑏 above, return 10 rows and 7 rows in the result set respectively, then what is one possible number of rows returned by the SQL query 𝑐 ?
- A.
3
- B.
7
- C.
10
- D.
21
Attempted by 937 students.
Show answer & explanation
Correct answer: C
Answer: 10 is a possible number of rows.
Explanation: Let A be the set of rows with Age>21 and B be the set of rows with Height>180.
We are given |A| = 10 and |B| = 7.
The size of the union is |A ∪ B| = |A| + |B| − |A ∩ B|.
The intersection |A ∩ B| can be any integer from 0 up to 7 (at most the smaller set).
Therefore |A ∪ B| can range from 10 + 7 − 7 = 10 up to 10 + 7 − 0 = 17.
10 occurs when all rows with Height>180 are already included among the rows with Age>21 (so the Height>180 set is a subset of the Age>21 set).
A video solution is available for this question — log in and enroll to watch it.