SQL Server Tutorial
In SQL Server, ORDER BY clause is used to sort the rows in either ascending or descending order.
SELECT column_name1[, column_name2, ....] FROM table_name [ORDER BY column_name | expression [ASC | DESC] [, column_name | expression [ASC | DESC]...]
ASC and DESC are the sorting order, ASC is the ascending order and DESC is the descending order.
ASC is the default sort order.
Let us consider the example 'Employee' database table.
To get the rows from Employee table in ascending order based on Country column.
SELECT Name, DeptId, City, Country, Email, Salary FROM Employee ORDER BY Country ASCOutput:
To get the rows from Employee table in ascending order based on Country and City columns.
SELECT Name, DeptId, City, Country, Email, Salary FROM Employee ORDER BY Country, City ASCOutput:
To get the rows from Employee table in descending order based on Country column.
SELECT Name, DeptId, City, Country, Email, Salary FROM Employee ORDER BY Country DESCOutput:
To get the rows from Employee table in descending order based on Country and City columns.
SELECT Name, DeptId, City, Country, Email, Salary FROM Employee ORDER BY Country, City DESCOutput:
SQL Server Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page