UNION & UNION ALL — Concept Check
Questions on UNION & UNION ALL. UNION deduplicates results from two SELECT statements; UNION ALL is faster (no dedup); both require matching column count and compatible types.
Questions in this quiz
8 questions on UNION & UNION ALL — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have two tables, 'employees_current' and 'employees_archive', with identical structures. You want to combine them into a single result set without duplicates. Which SQL statement should you use?
- AUNION ALL
- BUNION
- CINTERSECT
- DJOIN
2.A report query using UNION ALL is running significantly faster than one using UNION. What is the most likely reason for this?
- AUNION ALL skips deduplication, which is computationally expensive.
- BUNION ALL uses indexes more efficiently than UNION.
- CUNION ALL compresses data better than UNION.
- DUNION ALL uses less memory than UNION.
3.You are merging data from 'sales_2021' and 'sales_2022' tables. You know there are no duplicates. Which operation is more efficient?
- AUNION
- BEXCEPT
- CINTERSECT
- DUNION ALL
4.A developer claims that UNION ALL can be used even if the SELECT statements have different numbers of columns. What is the issue with this statement?
- AUNION ALL requires an ORDER BY clause.
- BUNION ALL can only be used with identical tables.
- CUNION ALL requires the same number of columns in each SELECT.
- DUNION ALL automatically removes duplicates.
5.Why might a UNION query be slower than expected when combining large datasets?
- AIt uses complex joins internally.
- BIt sorts or hashes the result set to remove duplicates.
- CIt compresses data before returning results.
- DIt requires all data to be loaded into memory.
6.You have a UNION query combining 'active_users' and 'inactive_users' tables. The result is larger than expected. What might be the reason?
- AThe query uses UNION ALL, which includes duplicates.
- BThe query uses EXCEPT, which excludes certain rows.
- CThe query uses UNION, which removes duplicates.
- DThe query uses INTERSECT, which includes only common rows.
7.A developer uses UNION ALL to combine results from 'products_us' and 'products_eu'. They notice duplicate entries. What should they do to remove duplicates?
- AAdd a DISTINCT clause to each SELECT statement.
- BUse a JOIN instead of UNION ALL.
- CSwitch to using UNION instead of UNION ALL.
- DAdd an ORDER BY clause to sort results.
8.You need to apply an ORDER BY clause to a UNION result. Where should it be placed?
- AInside a WITH clause.
- BBefore the UNION keyword.
- CAt the end of the entire UNION query.
- DAfter each SELECT statement.