ORDER BY & GROUP BY
In this lesson, we will learn about the ORDER BY and GROUP BY clauses.
We'll cover the following
The ORDER BY clause
The SQL ORDER BY clause is used to sort the data of one or more columns in ascending or descending order. Some databases sort the query results in ascending order by default.
Syntax
The basic syntax of the ORDER BY
clause is as follows:
SELECT column-list
FROM table_name
WHERE condition
ORDER BY column1, column2, .. columnN;
You can use more than one column in the ORDER BY clause. Make sure whatever column you are using to sort is in the column-list.
Example
We will sort the CUSTOMERS table in ascending order by the NAME
column:
Get hands-on with 1400+ tech skills courses.