Until now, we have been showing simple SELECT commands both with and without conditions. The SELECT command has a whole list of extensions that can be used to further filter and manipulate the data received from the database.
When we pulled data from the database table in the query examples earlier, MySQL returned the data in the same order it was placed in the table. For the most part, this works just fine because we just want to get the data out of the database. At other times, it might be important that the data be ordered in some specific fashion. For example, suppose you want to sort the data in ascending order (the default) based on the username:
mysql> SELECT * FROM person ORDER BY username;
+---------+-----------+----------+
| acc_id | username | password |
+---------+-----------+----------+
| 1000003 | John | jhn |
| 1000004 | Michael | Mic |
+---------+-----------+----------+
2 rows in set (0.00 sec)
As you can see in the output from the query, the data is displayed in alphabetical order based on the username. You can also sort based on a numeric column
mysql> SELECT * FROM person ORDER BY id;
+---------+-----------+----------+
| id | username | password |
+---------+-----------+----------+
| 1000003 | John | jhn |
| 1000004 | Michael | Mic |
+---------+-----------+----------+
2 rows in set (0.00 sec)