Challenge - 5 Problems
UNION ALL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of UNION ALL with duplicate rows
Consider two tables Employees_A and Employees_B with the following data:
Employees_A
id | name
1 | Alice
2 | Bob
Employees_B
id | name
2 | Bob
3 | Charlie
What is the result of the following query?
Employees_A
id | name
1 | Alice
2 | Bob
Employees_B
id | name
2 | Bob
3 | Charlie
What is the result of the following query?
SELECT id, name FROM Employees_A
UNION ALL
SELECT id, name FROM Employees_B;
Attempts:
2 left
💡 Hint
UNION ALL includes all rows from both queries, including duplicates.
✗ Incorrect
UNION ALL returns all rows from both tables without removing duplicates. Since '2 | Bob' appears in both tables, it appears twice in the result.
❓ query_result
intermediate2:00remaining
Counting rows after UNION ALL
Given two tables Orders_2023 and Orders_2024 each with 5 rows, where 2 rows are identical in both tables, what is the total number of rows returned by this query?
SELECT * FROM Orders_2023
UNION ALL
SELECT * FROM Orders_2024;
Attempts:
2 left
💡 Hint
UNION ALL does not remove duplicates, so all rows from both tables are included.
✗ Incorrect
UNION ALL returns all rows from both tables, so total rows = 5 + 5 = 10, even if some rows are duplicates.
📝 Syntax
advanced2:00remaining
Identify the syntax error in UNION ALL query
Which of the following SQL queries will cause a syntax error?
Attempts:
2 left
💡 Hint
UNION ALL requires the same number of columns in both SELECT statements.
✗ Incorrect
Option C selects two columns in the first query but only one in the second, causing a syntax error.
❓ optimization
advanced2:00remaining
Performance impact of UNION ALL vs UNION
Which statement about performance is true when comparing
UNION ALL and UNION?Attempts:
2 left
💡 Hint
Removing duplicates requires extra work.
✗ Incorrect
UNION removes duplicates which requires sorting or hashing, making it slower than UNION ALL which simply concatenates results.
🧠 Conceptual
expert2:00remaining
Effect of UNION ALL on duplicate rows with NULL values
Consider two tables Table1 and Table2 each having a row with values (NULL, 'X'). What will be the result of this query?
Specifically, how many rows with (NULL, 'X') will appear in the result?
SELECT col1, col2 FROM Table1
UNION ALL
SELECT col1, col2 FROM Table2;
Specifically, how many rows with (NULL, 'X') will appear in the result?
Attempts:
2 left
💡 Hint
UNION ALL includes all rows even if they contain NULLs and duplicates.
✗ Incorrect
UNION ALL does not remove duplicates, so both rows with (NULL, 'X') appear in the result.