SQL ORDER BY Clause

ORDER BY CLAUSE:-  The ORDER BY Clause is used to sort the result in ascending or descending order. By Default ORDER BY clause sorts the record in Ascending order.

SYNTAX:-

SELECT  column1 , column2 , ...
FROM table_name
WHERE condition
ORDER BY  column1 , column2 , ... ASC|DESC ;

EXAMPLE:-

Consider the CUSTOMERS table having the following records:- 


The following example sort the column CustomerID, Name and Salary in Ascending order using ORDER BY Name.

Example:-

SELECT CustomerID, Name , Salary

FROM CUSTOMERS

ORDER BY Name  ;


OUTPUT:-


The following example sorts the column CustomerID, Name and Salary in Descending order using ORDER BY Age.

Example:-

SELECT CustomerID, Name, Salary

FROM CUSTOMERS

ORDER BY Age DESC ;

OUTPUT:-


Comments

Popular posts from this blog

ASP.NET Overview

SQL AND ,OR, NOT Operators

SQL Joins