order by clause

Returns query results in the specified columns in sorted order.

Syntax

[Start of select statement]
[order by
	{[table_name.| view_name.]
		column_name | select_list_number | expression}
		[asc | desc] 
	[,{[table_name.| view_name.]
		column_name | select_list_number | expression}
		[asc | desc]]...]
[End of select statement]

Parameters

Examples

Usage

See also sp_configure, sp_helpsort, sp_lock, sp_sysmon in Reference Manual: Procedures.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Specifying new column headings in the order by clause of a select statement when the union operator is used is a Transact-SQL extension.

The behavior of order by when identical table column name and column alias name exist is a vendor-specific extension of the ANSI SQL standard.

Related reference
compute Clause
declare
group by and having Clauses
select
where clause
set