SQL Order by
What is the ORDER BY Clause in SQL?
The SQL ORDER BY clause sorts the results of a SELECT statement in either ascending or descending order based on one or more columns.
Here’s the syntax:
SELECT column1, column2, ... FROM table_name ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;
You can use “DESC” with the SQL ORDER BY to list the rows based on the column you choose. In this example, the data follows the descending order of the year launch.
SELECT * FROM sandbox.tv_show ORDER BY year_launch DESC;
If you have text instead of a number, you can order alphabetically. To list from A-Z, use ASC as follows.
Note the “sandbox.” before the table name means the schema that holds the table in Coginiti.