Challenge - 5 Problems
EXCEPT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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');
Attempts:
2 left
💡 Hint
Think about which employees are not managers.
✗ Incorrect
The query selects employees whose names are not in the Managers table, so it returns Alice and Charlie.
❓ query_result
intermediate2: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?Attempts:
2 left
💡 Hint
MySQL does not support EXCEPT. Use a subquery with NOT EXISTS or NOT IN.
✗ Incorrect
Option A uses NOT EXISTS to find rows in TableA that have no matching id in TableB, which is the correct EXCEPT equivalent.
📝 Syntax
advanced2: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.
Attempts:
2 left
💡 Hint
MySQL does not support EXCEPT keyword.
✗ Incorrect
MySQL does not support the EXCEPT keyword, so option D will cause a syntax error.
❓ optimization
advanced2: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?Attempts:
2 left
💡 Hint
Consider how joins and subqueries perform on large tables.
✗ Incorrect
LEFT JOIN with IS NULL is often more efficient than NOT IN or NOT EXISTS on large tables in MySQL.
🧠 Conceptual
expert3:00remaining
Why does NOT IN sometimes produce unexpected results compared to NOT EXISTS in MySQL?
Consider these two queries to find rows in
1)
2)
Why might query 1 return no rows even if some products are not discontinued?
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?
Attempts:
2 left
💡 Hint
Think about how NULL values affect NOT IN.
✗ Incorrect
If the subquery returns NULL, NOT IN returns no rows because NULL comparison is unknown, causing unexpected results.