0
0
MySQLquery~5 mins

UNION and UNION ALL in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the UNION operator do in SQL?
UNION 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 ALL differ from UNION?
UNION ALL combines results from multiple SELECT queries but keeps all duplicates, showing every row from each query.
Click to reveal answer
intermediate
Can UNION be used with SELECT queries that have different numbers of columns?
No, all SELECT queries combined with UNION or UNION ALL must have the same number of columns with compatible data types.
Click to reveal answer
intermediate
Why might you choose UNION ALL over UNION?
Use UNION ALL when you want to keep duplicates and improve performance because it does not check for duplicates like UNION does.
Click to reveal answer
beginner
What happens if you use UNION on two queries that return the same rows?
UNION will show each duplicate row only once, removing any repeated rows from the combined result.
Click to reveal answer
Which SQL operator removes duplicate rows when combining results?
AUNION ALL
BINTERSECT
CJOIN
DUNION
What must be true about the SELECT statements combined with UNION or UNION ALL?
AThey can have different numbers of columns.
BThey must have the same number of columns with compatible data types.
CThey must select from the same table.
DThey must use WHERE clauses.
Which operator is faster when you don't need to remove duplicates?
AUNION ALL
BJOIN
CUNION
DGROUP BY
If two SELECT queries return the same row, how many times will it appear in the result of UNION ALL?
ATwice
BDepends on the database
CZero times
DOnce
Which SQL operator combines results but does not remove duplicates?
AEXCEPT
BUNION
CUNION ALL
DINTERSECT
Explain the difference between UNION and UNION ALL in SQL.
Think about how duplicates are handled and when you might want to keep them.
You got /4 concepts.
    What rules must SELECT queries follow to be combined using UNION or UNION ALL?
    Focus on the structure of the SELECT statements.
    You got /4 concepts.