MariaDB ORDER BY Clause

In MariaDB database, ORDER BY Clause is used to sort the records in your result set in ascending or descending order.

Syntax:


SELECT expressions
FROM tables
[WHERE conditions]
ORDER BY expression [ ASC | DESC ]; 

# Note: You can sort the result without using ASC/DESC attribute. Bydefault the result will be sorted in ascending order.


# ORDER BY Clause without using ASC/DESC attributes

Use the "Employees" table, having the following data:

Mariadb Order by clause 1

Example:


SELECT * FROM Employees
WHERE name LIKE '%L%'
ORDER BY id; 

Output:

Mariadb Order by clause 2

# ORDER BY Clause with DESC Attribute


SELECT * FROM Employees
ORDER BY id DESC; 

Output:

Mariadb Order by clause 3

# ORDER BY Clause with ASC Attribute


SELECT * FROM Employees
ORDER BY id DESC; 

Output:

Mariadb Order by clause 4