SQL Server Performance, DBA Best Practices & Enterprise Data Solutions | MyTechMantra
Home » SQL Server Tutorial » SQL Server ORDER BY Clause T-SQL Tutorial with Examples

SQL Server ORDER BY Clause T-SQL Tutorial with Examples

Previous Page.. Begin Tutorial.. Next Page..

The ORDER BY Clause is used to order the result set in ascending or descending order. By default, when ORDER BY clause is used the result set is ordered in the ascending order.

This is Part 4 of 40 Part SQL Server T-SQL Tutorial. Click here to read it from the beginning….

ORDER BY Clause Syntax

SELECT column1, column2
	FROM schema.tablename
ORDER BY column1, column2 ASC|DESC
GO

ORDER BY ASC Example

Below query will fetch FirstName and LastName of all the records from Person’s table and order the results in ascending order. Even if you don’t specify the ASC still the result set will be retrieved in ascending order by default in SQL Server.

Use AdventureWorks2016
GO

SELECT
	  FirstName
	, LastName 
FROM Person.Person
	Order by FirstName ASC
GO
ORDER BY ASC Example in SQL Server


ORDER BY DESC Example

Below query will fetch FirstName and LastName of all the records from Person’s table and order the results in descending order.

Use AdventureWorks2016
GO

SELECT
	  FirstName
	, LastName 
FROM Person.Person
	Order by LastName DESC
GO
ORDER BY DESC Example in SQL Server


ORDER BY Multiple Column Example

The data is sorted in descending order and the data is sorted by FirstName and LastName. It means it is first ORDERED by FirstName and if some records has same FirstName then it is order by LastName. 

You can see in the snippet below that rows 4 to 15 has same First Name which is Aaron and therefore the records from 4 to 15 are sorted by LastName in the descending order as specified in the query.

Use AdventureWorks2016
GO

SELECT
	  FirstName
	, LastName 
FROM Person.Person
	Order by FirstName, LastName DESC
GO
ORDER BY Multiple Column Example in SQL Server

Click Next Page button to continue reading the topics and click on the Previous Page button to revisit the previous topic.

Previous Page.. Begin Tutorial.. Next Page..

Ashish Kumar Mehta

Ashish Kumar Mehta is a distinguished Database Architect, Manager, and Technical Author with over two decades of hands-on IT experience. A recognized expert in the SQL Server ecosystem, Ashish’s expertise spans the entire evolution of the platform—from SQL Server 2000 to the cutting-edge SQL Server 2025.

Throughout his career, Ashish has authored 500+ technical articles across leading technology portals, establishing himself as a global voice in Database Administration (DBA), performance tuning, and cloud-native database modernization. His deep technical mastery extends beyond on-premises environments into the cloud, with a specialized focus on Google Cloud (GCP), AWS, and PostgreSQL.

As a consultant and project lead, he has architected and delivered high-stakes database infrastructure, data warehousing, and global migration projects for industry giants, including Microsoft, Hewlett-Packard (HP), Cognizant, and Centrica PLC (UK) / British Gas.

Ashish holds a degree in Computer Science Engineering and maintains an elite tier of industry certifications, including MCITP (Database Administrator), MCDBA (SQL Server 2000), and MCTS. His unique "Mantra" approach to technical training and documentation continues to help thousands of DBAs worldwide navigate the complexities of modern database management.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.