0
0
MySQLquery~10 mins

EXCEPT equivalent 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 placed orders but exclude those who have returned items.

MySQL
SELECT customer_id FROM orders WHERE status = 'placed' [1] SELECT customer_id FROM returns WHERE status = 'returned';
Drag options to blanks, or click blank then click option'
AMINUS
BINTERSECT
CUNION
DEXCEPT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNION instead of EXCEPT returns all rows from both queries.
Using INTERSECT returns only common rows, not the difference.
2fill in blank
medium

Complete the code to find products sold but not returned using a LEFT JOIN and filtering NULLs.

MySQL
SELECT p.product_id FROM products p LEFT JOIN returns r ON p.product_id = r.product_id WHERE r.product_id [1];
Drag options to blanks, or click blank then click option'
AIS NOT NULL
BIS NULL
C= NULL
D<> NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using '= NULL' or '<> NULL' which are invalid in SQL.
Using IS NOT NULL which finds matched rows instead.
3fill in blank
hard

Fix the error in the query that tries to find employees who worked on projects but not on project 5.

MySQL
SELECT employee_id FROM project_assignments WHERE project_id != [1];
Drag options to blanks, or click blank then click option'
A5
BNULL
C'5'
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numeric IDs causing type mismatch.
Using NULL with != which always returns false.
4fill in blank
hard

Fill both blanks to create a query that selects all students who took Math but not Science using NOT EXISTS.

MySQL
SELECT student_id FROM enrollments e1 WHERE course = [1] AND NOT EXISTS (SELECT 1 FROM enrollments e2 WHERE e2.student_id = e1.student_id AND course = [2]);
Drag options to blanks, or click blank then click option'
A'Math'
B'Science'
C'History'
D'English'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the courses in the blanks.
Forgetting quotes around course names.
5fill in blank
hard

Fill all three blanks to write a query that lists all employees who are in the sales department but not in the marketing department using a subquery with NOT IN.

MySQL
SELECT employee_id FROM employees WHERE department = [1] AND employee_id NOT IN (SELECT employee_id FROM employees WHERE department = [2] AND status = [3]);
Drag options to blanks, or click blank then click option'
A'Sales'
B'Marketing'
C'Active'
D'Inactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong department names or missing quotes.
Not filtering by status in the subquery.