Chapter 10 — Quiz

12 questions. Answers at the bottom.


Multiple choice

Q1. Set operations combine query results by: - A) Adding columns (widening rows) - B) Adding rows (stacking results) - C) Sorting - D) Grouping

Q2. "Union compatibility" requires: - A) Identical table names - B) Same number of columns, in order, with compatible types - C) The same primary key - D) An index on each column

Q3. UNION vs UNION ALL: - A) Identical - B) UNION removes duplicates; UNION ALL keeps them - C) UNION ALL removes duplicates - D) UNION keeps duplicates

Q4. Which is generally faster, when both are correct for the task? - A) UNION - B) UNION ALL (no dedup step) - C) Always the same - D) Neither runs

Q5. INTERSECT returns rows that are: - A) In either query - B) In both queries - C) In the first but not the second - D) Duplicated

Q6. EXCEPT returns rows that are: - A) In both - B) In either - C) In the first but not the second - D) Sorted

Q7. Output column names in a set operation come from: - A) The second query - B) The first query - C) Both, combined - D) Alphabetical order

Q8. An ORDER BY on a UNION query goes: - A) In each SELECT - B) Once, at the very end (sorts the combined result) - C) Before the UNION - D) It's not allowed

Q9. EXCEPT is the set-algebra form of: - A) A join - B) A difference / anti-join - C) An aggregate - D) A projection

Q10. When mixing INTERSECT with UNION/EXCEPT, you should: - A) Rely on default precedence - B) Use parentheses to make grouping explicit - C) Avoid it entirely - D) Always put INTERSECT last


True/False

Q11. UNION should be your default, and UNION ALL used only rarely. (True / False)

Q12. EXCEPT and NOT EXISTS can express the same anti-join, but NOT EXISTS is more flexible when you need extra columns or conditions. (True / False)

---

Answer key

Q1 — B. Set operations stack rows; joins widen rows.

Q2 — B. Same column count/order and compatible types.

Q3 — B. UNION dedupes; UNION ALL keeps duplicates.

Q4 — B. UNION ALL skips the dedup (sort/hash), so it's faster.

Q5 — B. INTERSECT = in both.

Q6 — C. EXCEPT = in the first, not the second (difference).

Q7 — B. The first query's column names win.

Q8 — B. One ORDER BY at the end sorts the whole combined result.

Q9 — B. EXCEPT is set difference — the anti-join in set form.

Q10 — B. INTERSECT binds tighter than UNION/EXCEPT; parenthesize to be safe.

Q11 — False. Prefer UNION ALL (faster); use UNION only when you specifically need duplicate removal.

Q12 — True. EXCEPT compares whole rows and returns only the selected columns; NOT EXISTS lets you keep other columns and add conditions.

Scoring: 10–12 solid; 7–9 re-read UNION vs UNION ALL; below 7, redo Exercises A and C.