ORDER BY in SQL
The syntax for an ORDER BY statement is as follows:
SELECT “column_name”
FROM “table_name”
[WHERE “condition”]
ORDER BY “column_name” [ASC, DESC]
The [] means that the WHERE statement is optional. However, if a WHERE clause exists, it comes before the ORDER BY clause. ASC means that the results will be shown in ascending order, and DESC means that the results will be shown in descending order. If neither is specified, the default is ASC.
It is possible to order by more than one column. In this case, the ORDER BY clause above becomes ORDER BY “column_name1” [ASC, DESC], “column_name2” [ASC, DESC]
Leave a Reply
Want to join the discussion?Feel free to contribute!