0
0
PostgreSQLquery~10 mins

Why set operations matter in PostgreSQL - Test Your Understanding

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

Complete the code to combine two tables and remove duplicates.

PostgreSQL
SELECT column_name FROM table1 [1] SELECT column_name FROM table2;
Drag options to blanks, or click blank then click option'
AJOIN
BUNION
CINTERSECT
DEXCEPT
Attempts:
3 left
💡 Hint
Common Mistakes
Using JOIN instead of UNION causes syntax errors.
Using INTERSECT returns only common rows, not all combined.
2fill in blank
medium

Complete the code to find common rows between two tables.

PostgreSQL
SELECT column_name FROM table1 [1] SELECT column_name FROM table2;
Drag options to blanks, or click blank then click option'
AJOIN
BUNION
CEXCEPT
DINTERSECT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION returns all unique rows, not just common ones.
Using EXCEPT returns rows in first query but not second.
3fill in blank
hard

Fix the error in the code to find rows in table1 but not in table2.

PostgreSQL
SELECT column_name FROM table1 [1] SELECT column_name FROM table2;
Drag options to blanks, or click blank then click option'
AEXCEPT
BUNION
CINTERSECT
DJOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INTERSECT returns common rows, not unique ones.
Using UNION returns all unique rows combined.
4fill in blank
hard

Complete the code to combine two tables including duplicates.

PostgreSQL
SELECT column_name FROM table1 [1] SELECT column_name FROM table2 ;;
Drag options to blanks, or click blank then click option'
AUNION ALL
BUNION
CINTERSECT
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION removes duplicates.
Missing semicolon causes syntax errors.
5fill in blank
hard

Fill all three blanks to find rows in table1 not in table2 and order results.

PostgreSQL
SELECT column_name FROM table1 [1] SELECT column_name FROM table2 [2] ORDER BY [3];
Drag options to blanks, or click blank then click option'
AEXCEPT
B;
Ccolumn_name
DUNION
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION returns all unique rows, not just differences.
Forgetting semicolon causes errors.
Ordering by a non-existent column causes errors.