0
0
MySQLquery~20 mins

EXCEPT equivalent in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
EXCEPT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this EXCEPT equivalent query?
Given two tables Employees and Managers with a single column name, what does the following query return?

SELECT name FROM Employees WHERE name NOT IN (SELECT name FROM Managers);
MySQL
CREATE TABLE Employees (name VARCHAR(20));
INSERT INTO Employees VALUES ('Alice'), ('Bob'), ('Charlie');
CREATE TABLE Managers (name VARCHAR(20));
INSERT INTO Managers VALUES ('Bob');
A[{"name": "Bob"}]
B[{"name": "Alice"}, {"name": "Charlie"}]
C[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}]
D[]
Attempts:
2 left
💡 Hint
Think about which employees are not managers.
query_result
intermediate
2:00remaining
Which query returns rows in TableA but not in TableB?
You want to find all rows in TableA that do not appear in TableB. Which of these queries correctly does that in MySQL?
ASELECT * FROM TableA WHERE NOT EXISTS (SELECT 1 FROM TableB WHERE TableB.id = TableA.id);
BSELECT * FROM TableA EXCEPT SELECT * FROM TableB;
CSELECT * FROM TableA WHERE id NOT IN (SELECT id FROM TableB);
DSELECT * FROM TableB WHERE id NOT IN (SELECT id FROM TableA);
Attempts:
2 left
💡 Hint
MySQL does not support EXCEPT. Use a subquery with NOT EXISTS or NOT IN.
📝 Syntax
advanced
2:00remaining
Which query will cause a syntax error in MySQL?
Identify the query that will cause a syntax error in MySQL when trying to find rows in Table1 not in Table2.
ASELECT * FROM Table1 LEFT JOIN Table2 ON Table1.id = Table2.id WHERE Table2.id IS NULL;
BSELECT * FROM Table1 WHERE NOT EXISTS (SELECT 1 FROM Table2 WHERE Table2.id = Table1.id);
CSELECT * FROM Table1 WHERE id NOT IN (SELECT id FROM Table2);
DSELECT * FROM Table1 EXCEPT SELECT * FROM Table2;
Attempts:
2 left
💡 Hint
MySQL does not support EXCEPT keyword.
optimization
advanced
2:00remaining
Which query is the most efficient EXCEPT equivalent in MySQL for large tables?
You want to find rows in Orders that are not in ShippedOrders. Which query is generally the most efficient in MySQL for large datasets?
ASELECT * FROM Orders WHERE id NOT IN (SELECT id FROM ShippedOrders);
BSELECT * FROM Orders WHERE NOT EXISTS (SELECT 1 FROM ShippedOrders WHERE ShippedOrders.id = Orders.id);
CSELECT Orders.* FROM Orders LEFT JOIN ShippedOrders ON Orders.id = ShippedOrders.id WHERE ShippedOrders.id IS NULL;
DSELECT * FROM Orders EXCEPT SELECT * FROM ShippedOrders;
Attempts:
2 left
💡 Hint
Consider how joins and subqueries perform on large tables.
🧠 Conceptual
expert
3:00remaining
Why does NOT IN sometimes produce unexpected results compared to NOT EXISTS in MySQL?
Consider these two queries to find rows in Products not in Discontinued:

1) SELECT * FROM Products WHERE id NOT IN (SELECT id FROM Discontinued);
2) SELECT * FROM Products WHERE NOT EXISTS (SELECT 1 FROM Discontinued WHERE Discontinued.id = Products.id);

Why might query 1 return no rows even if some products are not discontinued?
ABecause NOT IN returns no rows if the subquery returns any NULL values.
BBecause NOT EXISTS is slower and less reliable than NOT IN.
CBecause NOT IN only works with numeric columns.
DBecause NOT EXISTS requires indexes to work correctly.
Attempts:
2 left
💡 Hint
Think about how NULL values affect NOT IN.