Sunday , December 22 2024

Order By Clause in SQL Server(TSQL)

 

With Order By Clause, you can sort the records returned as a result of the Select statement as ascending or descending according to the column you specify. Let’s make two examples that sort by numbers and letters.

Create a table to use in our examples and add a few records.

Example1: Sort numeric values with Order By Clause

The following command lists the records in the table from smaller to bigger according to the ID column.

The following command lists the records in the table from bigger to smaller according to the ID column.

Example2: Sorting Text Values with Order By Clause

With the following command, we sort the records in the table from A to Z according to the Name column.

With the following command, we sort the records in the table from Z to A according to the Name column.

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *