Recall & Review
beginner
What does the SQL UNION operator do?
The UNION operator combines the results of two or more SELECT queries into a single result set, removing duplicate rows.
Click to reveal answer
beginner
How does UNION differ from UNION ALL?
UNION removes duplicate rows from the combined result, while UNION ALL includes all rows, even duplicates.
Click to reveal answer
intermediate
What must be true about the SELECT statements used with UNION?
Each SELECT must have the same number of columns, and the columns must have compatible data types in the same order.
Click to reveal answer
intermediate
Can you use ORDER BY with UNION? If yes, where?
Yes, ORDER BY can be used only once at the end of the entire UNION query to sort the combined result set.
Click to reveal answer
intermediate
What happens if the SELECT statements in a UNION have different column names?
The column names in the final result come from the first SELECT statement; later SELECTs' column names are ignored.
Click to reveal answer
What does the UNION operator do in SQL?
✗ Incorrect
UNION combines results from multiple SELECTs and removes duplicate rows.
Which of the following is true about SELECT statements in a UNION?
✗ Incorrect
All SELECTs in a UNION must have the same number of columns with compatible data types.
What is the difference between UNION and UNION ALL?
✗ Incorrect
UNION removes duplicate rows, while UNION ALL includes all rows.
Where can you place ORDER BY when using UNION?
✗ Incorrect
ORDER BY can only be used once at the end to sort the combined result.
If the first SELECT has columns (id, name) and the second SELECT has columns (user_id, username), what will the final column names be after UNION?
✗ Incorrect
The final column names come from the first SELECT statement.
Explain how the UNION operator works and what rules must be followed when combining SELECT statements.
Think about how two lists of data can be merged without repeats.
You got /5 concepts.
Describe the difference between UNION and UNION ALL and when you might use each.
Consider if you want to keep or remove repeated rows.
You got /4 concepts.