SQL Flow Field Guide

SELECT - ORDER BY clause

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

sorts the result; ORDER BY is the only guarantee of output order

What changes

Input
projected rows (can also reference source columns and aliases)
Output or change
ordered rows

Syntax at a glance

ORDER BY order_by_expression [ COLLATE collation_name ] [ ASC | DESC ] [ , ...n ] [ <offset_fetch> ]

Work example

A client needs rows in a repeatable order for display, paging, or a top-N result.

Sort on a unique key after the user-facing columns. Run the same query twice and compare row order.

Check your work SELECT - ORDER BY clause. Tied values have a stable final tie-breaker and both runs return the same order.

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