A simple example of UNION and UNION ALL with two table variables. UNION removes the duplicate rows, while UNION ALL keeps every row from both tables.
Top and Bottom Rows With a CTE in SQL Server: Part 2
Top and bottom rows with a CTE come from two ordered queries, one for each end of the table. This follow-up tests the reader’s single-CTE version and a two-CTE version on SQL Server 2025. It also compares a ROW_NUMBER version that read 336 pages against 4 for TOP, and shows what ties, empty tables and one-row tables return.
SQL SERVER – Three Rules to Use UNION
The three rules to use UNION from Ben Forta’s T-SQL book: two or more SELECT statements, the same columns in the same order, and compatible data types.
SQL SERVER – Insert Multiple Records Using One Insert Statement – Use of UNION ALL
Insert multiple records with one INSERT statement by combining SELECT and UNION ALL, instead of a separate INSERT for every row. SQL Server 2008 has a newer way.



