Order By
ORDER BY Clause is used to sort the result-set records into ascending or descending.
The ASC keyword used for sort in ascending order (by default).
The DESC keyword used for sort in descending order.
For Ascending Order :-
Syntax :-
SELECT column1, column2,.......,columnN
FROM table_name
ORDER BY column_names ....ASC;
Example : Let' see how to used ORDER BY clause for Ascending order.
Query :
Output :
SELECT *
FROM customers
ORDER BY Name ASC;
Now, you can see this output, which would sort the result in an ascending order by the Name.
For Descending Order :-
Syntax :-
SELECT column1, column2,.......,columnN
FROM table_name
ORDER BY column_names ....DESC;
Example :Let' see how to used ORDER BY clause for Descending order.
Query :
Output :
SELECT *
FROM customers
ORDER BY Name DESC;
Now, you can see this output, which would sort the result in an descending order by the Name.
0 Comments