ORDER BY Clause

The ORDER BY clause is used to sort a selected set of records in ascending or descending order. By default, rows are sorted in ascending order. If you want to specify the sorting order, you can append ASC for ascending or DESC for descending at the end of the expression.

Formula:

SELECT column1
, column2
, column3
FROM Table1
ORDER BY column1, column2, column3 ASC;

You can also combine different sorting types, for example, column1 ASC, column2 DESC, column3 ASC. Another important aspect is the ability to sort without writing the full column names. The query then looks like this:

SELECT column1
, column2
, column3
FROM Table1
ORDER BY 1, 2, 3 ASC;

Interesting article? Share further!

Leave A Comment