Using MS SQL Order By

The ORDER BY function is used to sort the records in a query written in MS SQL. Straight or Reverse sorting can be done.

For reverse sorting, DESC must be written at the end of the field or fields to be sorted. For straight sorting, nothing needs to be written, but in some cases ASC is required.

Let's sort the records of our table named PRODUCTS according to the NAME field in reverse.

NAME PRICE
Fruit Juice 5
Cake 10
Beer 12
Soda 8
Water 6
Salt 15
Sugar 16

The query to be written for this should be as follows.

SELECT * FROM PRODUCTS ORDER BY NAME DESC

Bize döndüreceği sonuç aşağıdaki gibi olur.

NAME PRICE
Water 6
Sugar 16
Soda 8
Salt 15
Fruit Juice 5
Cake 10
Beer 12


You May Interest

Where are SQL Server Usernames and Passwords Stored in the SQL Se ...

What is the Difference Between UNION and UNION ALL in SQL Server ...

MS SQL List of Records in All Tables

MS SQL Show Only Date of Current Time

What is the Difference Between CHAR and VARCHAR Datatypes in SQL ...