SQL Flow Field Guide

Set - UNION

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

set union

What changes

Input
two or more query results with matching column count
Output or change
combined rows; UNION removes duplicates, UNION ALL keeps them

Syntax at a glance

{ <query_specification> | ( <query_expression> ) } { UNION [ ALL ] { <query_specification> | ( <query_expression> ) } [ ...n ] }

Work example

A report needs Set - UNION to define which rows satisfy a compound search condition.

Test a match, a nonmatch, and NULL. Write the expected TRUE, FALSE, or UNKNOWN result before running the filter.

Check your work Set - UNION. The rows kept by Set - UNION are exactly those whose complete condition evaluates to TRUE.

Practice SQL

Open in SQL Flow
SELECT Code FROM (VALUES (1), (2)) AS FirstSet(Code)
UNION
SELECT Code FROM (VALUES (2), (3)) AS SecondSet(Code);

Open Microsoft Learn for full syntax, permissions, and details for your version.