saftutorials.com
MYSQL ORDER

MySQL ORDER BY keyword is used to sort the result of a table in ascending or descending order. By default ORDER BY keyword sort the result of a table in ascending order and if you want to sort the result of the table in descending order then you have to MySQL DESC keyword.


Syntax of ORDER BY

SELECT column1, column2, ...

FROM table_name

ORDER BY column1 ASC OR DESC;


There are some examples of ORDER By

SELECT * FROM student ORDER BY student_name;

Above MYSQL QUERY select all the column of student table and sorted by student name in ascending order.


SELECT * FROM student ORDER BY student_name DESC;

Above MYSQL QUERY select all the column of student table and sorted by student name in descending order.


SELECT * FROM student ORDER BY student_name, student_enrollment_no;

Above MYSQL QUERY select all the column of student table and sorted by student name and student enrollment_no in ascending order.


SELECT * FROM student ORDER BY student_name DESC, student_enrollment_no DESC;

Above MYSQL QUERY select all the column of student table and sorted by student name and student enrollment_no in descending order.


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic