0
0
MySQLquery~10 mins

Subqueries with EXISTS in MySQL - Interactive Code Practice

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

Complete the code to select all customers who have at least one order.

MySQL
SELECT customer_id FROM customers WHERE EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.[1]);
Drag options to blanks, or click blank then click option'
Aid
Border_id
Corder_date
Dcustomer_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column like order_id or order_date in the WHERE clause.
Confusing the table aliases or column names.
2fill in blank
medium

Complete the code to find products that have never been ordered.

MySQL
SELECT product_id FROM products WHERE NOT EXISTS (SELECT 1 FROM order_items WHERE order_items.product_id = products.[1]);
Drag options to blanks, or click blank then click option'
Aproduct_id
Border_id
Cid
Dquantity
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column like order_id or quantity in the WHERE clause.
Forgetting to use NOT EXISTS to find products never ordered.
3fill in blank
hard

Fix the error in the query to select employees who manage at least one department.

MySQL
SELECT employee_id FROM employees WHERE EXISTS (SELECT 1 FROM departments WHERE departments.manager_id = employees.[1]);
Drag options to blanks, or click blank then click option'
Adepartment_id
Bemployee_id
Cmanager_id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong employee column like id or manager_id.
Confusing the columns between employees and departments.
4fill in blank
hard

Fill both blanks to select customers who have placed orders with total amount greater than 1000.

MySQL
SELECT customer_id FROM customers WHERE EXISTS (SELECT 1 FROM orders WHERE orders.[1] = customers.[2] AND orders.total_amount > 1000);
Drag options to blanks, or click blank then click option'
Acustomer_id
Border_id
Cid
Dtotal_amount
Attempts:
3 left
💡 Hint
Common Mistakes
Using order_id or total_amount in the join condition.
Mixing up customer_id with id.
5fill in blank
hard

Fill all three blanks to select products that appear in orders with quantity greater than 5.

MySQL
SELECT product_id FROM products WHERE EXISTS (SELECT 1 FROM order_items WHERE order_items.[1] = products.[2] AND order_items.[3] > 5);
Drag options to blanks, or click blank then click option'
Aproduct_id
Bid
Cquantity
Dorder_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using order_id instead of product_id for the join.
Using id instead of product_id for products.
Checking order_id > 5 instead of quantity > 5.