SQL Flow Field Guide

geography::UnionAggregate

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

spatial aggregate UnionAggregate

What changes

Input
spatial values of each group
Output or change
one geometry/geography per group
Return type
SQL Server return type: geography

Syntax at a glance

UnionAggregate ( geography_operand )

Work example

Use geography.UnionAggregate to combine a grouped set of shapes into a union.

Group compatible SRIDs and test separated, touching, and overlapping inputs. Keep the geography type and SRID in the review.

Check your work The aggregate unions both overlapping polygons; the shared region is counted once.

Practice SQL

Open in SQL Flow

Open the SQL for a walkthrough. Run the example in SQL Server to check its result.

SELECT geography::UnionAggregate(v.shape).STGeometryType() AS union_type, geography::UnionAggregate(v.shape).STArea() AS union_area_m2 FROM (VALUES (geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326)), (geography::STGeomFromText('POLYGON((-122.351 47.656, -122.341 47.656, -122.341 47.661, -122.351 47.661, -122.351 47.656))', 4326))) AS v(shape);

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