UNION ALL for Pivot Alternative
UNION ALL for Pivot Alternative is a SQL statement in the Set Operations category. UNION ALL can create pivoted/cross-tabulated results without PIVOT syntax, by stacking multiple SELECT queries. It returns pivoted metric result. 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. A close relative is INTERSECT, which returns rows that appear in BOTH query results. Supported in PostgreSQL, SQL Server, Oracle. More about this category: Set-based operations — UNION, UNION ALL, INTERSECT, EXCEPT. Related Set Operations entries: UNION, UNION ALL, INTERSECT, EXCEPT / MINUS, INTERSECT ALL / EXCEPT ALL, Ordering Set Operations, TABLE Keyword, Set Operation Precedence. This page is part of the free SQL Reference documentation covering 762+ statements, functions, and clauses, each with syntax, parameters, return values, and examples for MySQL, PostgreSQL, SQL Server, and SQLite.