Challenge - 5 Problems
INTERSECT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find common customers using INTERSECT equivalent
Given two tables CustomersA and CustomersB with a column
customer_id, which query correctly returns the customer IDs present in both tables using MySQL syntax?MySQL
SELECT customer_id FROM CustomersA INTERSECT SELECT customer_id FROM CustomersB;
Attempts:
2 left
💡 Hint
MySQL does not support INTERSECT directly; think about how to find common values using subqueries.
✗ Incorrect
Option D uses a WHERE IN clause to select customer IDs from CustomersA that also exist in CustomersB, effectively mimicking INTERSECT behavior. Option D returns duplicates if multiple matches exist and may return more columns if not careful. Option D returns all unique customer IDs from both tables (union). Option D uses EXCEPT which is not supported in MySQL and would cause an error.
❓ query_result
intermediate2:00remaining
Using JOIN to simulate INTERSECT
Which query returns the same result as INTERSECT for two tables
Orders1 and Orders2 on column order_id in MySQL?MySQL
SELECT order_id FROM Orders1 INTERSECT SELECT order_id FROM Orders2;
Attempts:
2 left
💡 Hint
Think about how INNER JOIN returns only matching rows.
✗ Incorrect
Option A uses INNER JOIN to return only order_ids present in both tables, simulating INTERSECT. Option A returns order_ids in Orders1 but not in Orders2 (difference). Option A returns all unique order_ids from both tables (union). Option A returns order_ids in Orders1 but not in Orders2 (difference).
📝 Syntax
advanced2:00remaining
Identify the syntax error in INTERSECT simulation
Which of the following MySQL queries will cause a syntax error when trying to simulate INTERSECT?
Attempts:
2 left
💡 Hint
Check if MySQL supports the INTERSECT keyword.
✗ Incorrect
Option A uses INTERSECT which is not supported in MySQL and will cause a syntax error. Options A, B, and C are valid MySQL queries that simulate INTERSECT behavior.
❓ optimization
advanced2:00remaining
Optimizing INTERSECT equivalent query
Given large tables
EmployeesA and EmployeesB with column emp_id, which query is the most efficient way to find common emp_ids in MySQL?Attempts:
2 left
💡 Hint
Consider how JOINs and indexes affect performance on large datasets.
✗ Incorrect
Option B uses INNER JOIN with DISTINCT which is generally more efficient on large datasets if indexes exist on emp_id columns. Option B uses a subquery which can be slower. Option B returns union, not intersection. Option B uses LEFT JOIN with a filter which is less efficient than INNER JOIN.
🧠 Conceptual
expert3:00remaining
Understanding INTERSECT behavior with duplicates
Consider two tables
Table1 and Table2 each having duplicate values in column val. Which MySQL query best simulates the INTERSECT operation that returns each common value only once, regardless of duplicates?Attempts:
2 left
💡 Hint
INTERSECT returns unique common values, duplicates removed.
✗ Incorrect
Option C uses INNER JOIN with DISTINCT to return unique common values, matching INTERSECT behavior. Option C may return duplicates if Table1 has duplicates. Option C returns duplicates from the join. Option C returns all unique values from both tables (union).