0
0
PostgreSQLquery~10 mins

UNION and UNION ALL in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to combine results from two tables without duplicates.

PostgreSQL
SELECT name FROM employees [1] SELECT name FROM managers;
Drag options to blanks, or click blank then click option'
AUNION
BJOIN
CUNION ALL
DINTERSECT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION ALL when duplicates should be removed.
Using JOIN instead of UNION to combine rows.
2fill in blank
medium

Complete the code to combine all rows from two tables including duplicates.

PostgreSQL
SELECT product_id FROM sales_2023 [1] SELECT product_id FROM sales_2024;
Drag options to blanks, or click blank then click option'
AINTERSECT
BUNION ALL
CUNION
DEXCEPT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION instead of UNION ALL when duplicates are needed.
Using INTERSECT which returns only common rows.
3fill in blank
hard

Fix the error in the query to combine customer names from two tables.

PostgreSQL
SELECT customer_name FROM customers [1] ALL SELECT customer_name FROM clients;
Drag options to blanks, or click blank then click option'
AINTERSECT
BUNION
CJOIN
DUNION ALL
Attempts:
3 left
💡 Hint
Common Mistakes
Writing 'UNION ALL' with extra words or missing space.
Using JOIN instead of UNION ALL.
4fill in blank
hard

Fill both blanks to combine two queries and order the results by id.

PostgreSQL
SELECT id FROM table1 [1] SELECT id FROM table2 ORDER BY [2];
Drag options to blanks, or click blank then click option'
AUNION
BUNION ALL
Cid
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION ALL when duplicates should be removed.
Ordering by a column not in the SELECT list.
5fill in blank
hard

Fill all three blanks to combine two queries selecting user and score, keeping duplicates, and order by score descending.

PostgreSQL
SELECT user, score FROM scores_2022 [1] SELECT user, score FROM scores_2023 ORDER BY [2] [3];
Drag options to blanks, or click blank then click option'
AUNION
BUNION ALL
Cscore
DDESC
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION instead of UNION ALL when duplicates are needed.
Ordering ascending instead of descending.