0
0
PostgreSQLquery~10 mins

INTERSECT and EXCEPT 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 find common customers in both tables.

PostgreSQL
SELECT customer_id FROM orders_2023 [1] SELECT customer_id FROM orders_2024;
Drag options to blanks, or click blank then click option'
AINTERSECT
BUNION
CEXCEPT
DJOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION returns all unique rows from both tables, not just common ones.
Using EXCEPT returns rows from the first query that are not in the second.
2fill in blank
medium

Complete the code to find customers who ordered in 2023 but not in 2024.

PostgreSQL
SELECT customer_id FROM orders_2023 [1] SELECT customer_id FROM orders_2024;
Drag options to blanks, or click blank then click option'
AEXCEPT
BINTERSECT
CUNION
DJOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INTERSECT returns only common rows, not unique ones.
Using UNION combines all unique rows from both queries.
3fill in blank
hard

Fix the error in the query to find customers who ordered in 2024 but not in 2023.

PostgreSQL
SELECT customer_id FROM orders_2024 [1] SELECT customer_id FROM orders_2023;
Drag options to blanks, or click blank then click option'
AINTERSECT
BJOIN
CEXCEPT
DUNION ALL
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION ALL returns all rows including duplicates.
Using INTERSECT returns only common rows.
4fill in blank
hard

Fill both blanks to find customers who ordered in 2023 or 2024 but not both.

PostgreSQL
SELECT customer_id FROM orders_2023 [1] SELECT customer_id FROM orders_2024
EXCEPT
SELECT customer_id FROM orders_2023 [2] SELECT customer_id FROM orders_2024;
Drag options to blanks, or click blank then click option'
AUNION
BINTERSECT
CEXCEPT
DJOIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using EXCEPT instead of UNION in the first blank returns only unique to 2023.
Using UNION instead of INTERSECT in the second blank does not exclude common customers.
5fill in blank
hard

Fill all three blanks to find customers who ordered in 2023 but not in 2024, showing their names and IDs.

PostgreSQL
SELECT [1], customer_id FROM customers WHERE customer_id IN (
  SELECT customer_id FROM orders_2023 [2] SELECT customer_id FROM orders_2024
) [3] ORDER BY customer_id;
Drag options to blanks, or click blank then click option'
Acustomer_name
BEXCEPT
CLIMIT 10
DWHERE
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of LIMIT causes syntax errors at the end.
Using INTERSECT instead of EXCEPT returns common customers, not unique ones.