Back to course home
0% completed
Vote For New Content
ORDER BY Clause
ORDER BY
In MySQL, the ORDER BY
clause is used to sort the result set of a query based on one or more columns. It is typically used with the SELECT
statement to arrange the rows in a specific order.
Syntax
SELECT column1, column2 FROM table_name WHERE condition ORDER BY column1 [ASC | DESC], column2 [ASC | DESC];
Here's a brief explanation of the components:
- ASC: Ascending order (default). Rows are sorted from the smallest value to the largest value.
- DESC: Descending order. Rows are sorted from the largest value to the smallest value.
Example
Suppose we have an Employees
table as shown below:
and we want to retrieve the employee's records with age arranged in ascending order.
SELECT * FROM Employee ORDER BY Age ASC;
MYSQL
MYSQL
. . . .
The result of this query would be a table showing the employee's record in the following order:
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible