The ORDER BY clause is use to sort the data in ascending or descending order. Whenever you fetch the data from the database, it comes in By default the data is sorted in ascending order. To sort the records in descending order, use the DESC keyword and for ascending order use ASC.
Syntax of ORDER BY clause
Following is the syntax of ORDER BY clause, it gives you an idea about, how you can use while writing a SQL query.
SELECT * FROM table_name ORDER BY column_name ASC; //Ascending Order
SELECT * FROM table_name ORDER BY column_name DESC; //Descending Order
Examples of ORDER BY clause
For following examples used student table, below is the data from student table.
1) DESC : Sort the student data by descending order using division column.
2) ASC: Sort the student data by ascending order using division column.
Tags:
SQL