SQL ORDERBY CLAUSE
The SQL ORDER BY clause is used for sorting data in ascending and descending order based on one or more columns.
SQL Orderby Syntax
SELECT expressions FROM tables WHERE conditions ORDER BY expression [ASC | DESC];
SQL ORDERBY ASCENDING ORDER
This statement is used to sort data in ascending order.By default sql use ascending.
syntax
SELECT column_name FROM table_name WHERE column_name2 = 'xyz' ORDER BY column_name3;
SQL ORDERBY DESCENDING ORDER
This statement is used to sort data in descending order.
syntax
SELECT column_name FROM table_name WHERE column_name2 = 'xyz' ORDER BY column_name3 DESC;
SQL ORDERBY RANDOM
It fetch random data from database table.
syntax
SELECT column FROM table ORDER BY RAND () LIMIT 1
SQL ORDERBY LIMIT
It can be used retrieve limited rows from the database.
syntax
SELECT * FROM table_name WHERE column_name ="?" LIMIT 10