0
0
PostgreSQLquery~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL UNION operator do?
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 all queries.
Click to reveal answer
intermediate
Can you use UNION or UNION ALL 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 in a query?
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 row only once, removing duplicates from the combined result.
Click to reveal answer
Which SQL operator removes duplicate rows when combining results?
AUNION
BUNION ALL
CJOIN
DINTERSECT
If you want to combine results and keep all duplicates, which should you use?
AJOIN
BUNION
CEXCEPT
DUNION ALL
What must be true about the SELECT statements combined with UNION or UNION ALL?
AThey must use WHERE clauses.
BThey can have any number of columns.
CThey must have the same number of columns with compatible data types.
DThey must select from the same table.
Which operator is generally faster because it does not remove duplicates?
AUNION ALL
BUNION
CINTERSECT
DEXCEPT
What will the result of UNION be if two queries return identical rows?
AAll rows including duplicates
BOnly one copy of each duplicate row
CNo rows
DAn error
Explain the difference between UNION and UNION ALL in SQL.
Think about how duplicates are handled and performance.
You got /4 concepts.
    What are the requirements for SELECT statements when using UNION or UNION ALL?
    Consider the structure of the SELECT queries.
    You got /3 concepts.