Recall & Review
beginner
What are set operations in SQL?
Set operations combine results from two or more SELECT queries into a single result. Common set operations include UNION, INTERSECT, and EXCEPT.
Click to reveal answer
beginner
How does ORDER BY work with set operations?
ORDER BY sorts the final combined result of the set operation. It must be placed after all SELECT statements and set operators.
Click to reveal answer
intermediate
Can you use ORDER BY inside each SELECT of a set operation?
No, ORDER BY inside individual SELECTs is ignored unless you use TOP or LIMIT. The final ORDER BY after the set operation controls sorting.
Click to reveal answer
beginner
What happens if you use UNION without ORDER BY?
The combined result will have unique rows but the order is not guaranteed. To see sorted results, use ORDER BY after the UNION.
Click to reveal answer
beginner
Write a simple SQL query using UNION and ORDER BY.
Example:
SELECT name FROM students
UNION
SELECT name FROM teachers
ORDER BY name ASC;
Click to reveal answer
Where should ORDER BY be placed when using set operations like UNION?
✗ Incorrect
ORDER BY must come after all SELECT statements and set operations to sort the final combined result.
What does UNION do in SQL?
✗ Incorrect
UNION combines results from two queries and removes duplicate rows.
Can ORDER BY inside individual SELECT statements affect the final output order in a UNION?
✗ Incorrect
ORDER BY inside individual SELECTs is ignored for final sorting; only the ORDER BY after the set operation matters.
Which set operation returns only rows common to both queries?
✗ Incorrect
INTERSECT returns only rows that appear in both queries.
What will happen if you omit ORDER BY after a UNION?
✗ Incorrect
Without ORDER BY, the combined result has no guaranteed order.
Explain how to use ORDER BY with set operations like UNION in SQL.
Think about where the sorting happens after combining results.
You got /3 concepts.
Describe the difference between UNION and INTERSECT and how ORDER BY affects their results.
Focus on what rows each set operation returns and when sorting applies.
You got /3 concepts.