Sorting Data
Learn how to sort using the ORDER BY clause.
Revisiting report 1
Let’s revisit the part where we created a report listing salespersons. Here is what we did:
MySQL
SELECT DISTINCT SalesPersonFROM SalesData;
Although we had successfully generated the report, we overlooked the requirement that the names of the salespersons in the sample report should be sorted in ascending order.
To that end, SQL provides a mechanism to arrange the outcomes in either ascending or descending order.
The structure of such a query is outlined below:
SELECT column1, column2, ...FROM table_nameORDER BY column1, column2, ... ASC|DESC;
...