Recall & Review
beginner
What is the basic rule for column matching in SQL set operations like UNION?
The number of columns must be the same in all queries, and the data types of corresponding columns should be compatible.
Click to reveal answer
beginner
Can column names differ in the SELECT statements used in a UNION operation?
Yes, column names can differ. The result set uses the column names from the first SELECT statement.
Click to reveal answer
intermediate
Why must data types be compatible in set operations?
Because SQL combines rows from different queries into one result, incompatible data types can cause errors or unexpected results.
Click to reveal answer
beginner
What happens if the number of columns differs between SELECT statements in a UNION?
The SQL query will fail with an error because the columns do not match in number.
Click to reveal answer
intermediate
How does SQL handle NULL values in set operations when columns match?
NULL values are treated as valid data and included in the result set where they appear in any of the combined queries.
Click to reveal answer
In a UNION operation, what must be true about the SELECT statements?
✗ Incorrect
The number of columns and their data types must match, but column names and tables can differ.
If the first SELECT statement has columns (id, name) and the second has (user_id, username), what will be the column names in the UNION result?
✗ Incorrect
The result set uses the column names from the first SELECT statement.
What error occurs if SELECT statements in a UNION have different numbers of columns?
✗ Incorrect
SQL requires the same number of columns; otherwise, it raises a column count mismatch error.
Are data types required to be exactly the same in set operations?
✗ Incorrect
Data types must be compatible so SQL can combine the columns without errors.
How does SQL treat NULL values in set operations?
✗ Incorrect
NULL values are included as valid data in the combined result.
Explain the rules for matching columns in SQL set operations like UNION or INTERSECT.
Think about how SQL combines rows from multiple queries.
You got /4 concepts.
What errors or issues can arise if column matching rules are not followed in set operations?
Consider what happens if SQL tries to combine incompatible columns.
You got /4 concepts.