Skip to main content

Exam 7: Subqueries & Set Operations

Difficulty: Intermediate

Topics covered: Subqueries in WHERE, EXISTS, NOT EXISTS, UNION

Each question shows the target output. Write a SQL query that produces exactly those columns and rows.


Question 1

Find all customers who have placed at least one order. Use a subquery with IN. Return all columns from customers.

⌘ / Ctrl + Enter to run

Question 2

Find all products that have never appeared in a completed order. Use NOT IN. Return all columns from products.

⌘ / Ctrl + Enter to run

Question 3

Find all customers who have placed at least one completed order. Use EXISTS. Return customer_id and name.

⌘ / Ctrl + Enter to run

Question 4

Find all completed orders where total_amount is above the average total_amount of all completed orders. Return all columns from orders.

⌘ / Ctrl + Enter to run

Question 5

Use UNION to produce a single list of all customer_id values from the customers table combined with the distinct customer_id values from the orders table. Return a single column named customer_id.

⌘ / Ctrl + Enter to run
Donate to this project