Column Count Matching (Set Ops)
Column Count Matching (Set Ops) is a SQL statement in the Set Operations category. All SELECT lists in set operations must have the same number of columns. Data types must be compatible. The syntax is SELECT col1, col2, col3 FROM t1 UNION SELECT col1, col2, col3 FROM t2;. It returns column-count-matched result. A typical example: -- Correct (3 columns each): SELECT id, name, salary FROM employees UNION SELECT id, name, salary FROM former_employees; -- WRONG (different column counts): -- SELECT id, name FROM employees -- UNION -- SELECT id, name, salary FROM former_employees; -- ERROR: number of columns must match -- Fix with NULL padding: SELECT id, name, salary FROM employees UNION SELECT id, name, NULL FROM former_employees; -- Pad with NULL A close relative is UNION, which combines results from two queries, removing duplicate rows. Each SELECT must have the same number of columns. A close relative is UNION ALL, which like UNION but does NOT remove duplicate rows. Faster because no dedup is needed.