0
0
SQLquery~5 mins

UNION ALL with duplicates in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL UNION ALL operator do?
UNION ALL combines the results of two or more SELECT queries and includes all rows, even duplicates.
Click to reveal answer
beginner
How does UNION ALL differ from UNION?
UNION removes duplicate rows from the combined result, while UNION ALL keeps all duplicates.
Click to reveal answer
beginner
Given two tables with overlapping data, which operator would you use to keep all rows including duplicates?
Use UNION ALL to keep all rows including duplicates from both tables.
Click to reveal answer
beginner
Write a simple SQL query using UNION ALL to combine two tables named 'A' and 'B' with the same columns.
SELECT * FROM A UNION ALL SELECT * FROM B;
Click to reveal answer
intermediate
Why might you choose UNION ALL over UNION in a query?
Because UNION ALL is faster since it does not check for duplicates, and you want to keep all rows including duplicates.
Click to reveal answer
What happens to duplicate rows when using UNION ALL?
ADuplicates are kept
BDuplicates are removed
COnly one duplicate is kept
DQuery fails if duplicates exist
Which SQL operator removes duplicate rows when combining results?
AUNION ALL
BINTERSECT
CUNION
DEXCEPT
Which operator is generally faster when combining two result sets?
AUNION ALL
BUNION
CINTERSECT
DEXCEPT
If you want to combine two tables and keep all rows including duplicates, which query is correct?
ASELECT * FROM A UNION SELECT * FROM B;
BSELECT * FROM A UNION ALL SELECT * FROM B;
CSELECT * FROM A INTERSECT SELECT * FROM B;
DSELECT * FROM A EXCEPT SELECT * FROM B;
What is a key reason to use UNION ALL instead of UNION?
ATo filter rows
BTo remove duplicates
CTo sort results automatically
DTo improve query speed
Explain the difference between UNION and UNION ALL in SQL.
Think about how duplicates are handled and speed.
You got /3 concepts.
    Describe a scenario where using UNION ALL is better than UNION.
    Consider when duplicates are important and speed matters.
    You got /3 concepts.