Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:
The UNION family combines multiple query results into a single result set. To merge rows correctly, SQL needs the same column structure across all branches. This question checks whether each SELECT in a UNION must match in column count and have union-compatible data types.
Given Data / Assumptions:
Concept / Approach:
SQL aligns columns by ordinal position, not by name. Therefore, each SELECT must project the same number of columns. Their data types must be compatible so the DBMS can determine a common type for the final column. UNION removes duplicates; UNION ALL preserves all rows, but both require structural compatibility.
Step-by-Step Solution:
Verification / Alternative check:
Try a UNION where one SELECT has an extra column; the DBMS raises an error. Try incompatible types without casting; the DBMS rejects or implicitly converts within its rules.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming column names matter for alignment; forgetting explicit CAST to harmonize types; mismatched column counts.
Final Answer:
Correct
Discussion & Comments