MySQL sorting ORDER by
The ORDER BY operator sorts the selection rows of the SQL query by the field (table column).
SELECT id,login,password FROM user ORDER BY login
Sorting is possible in ascending or descending order.
Sort in descending
By default, sorting will be ascending (ASC).
If you want to sort in descending order, you need to add an operator (DESC).
SELECT id,login,password FROM user ORDER BY login DESC
Sorting by multiple fields
You can also sort by several columns of the table at once.
SELECT id,login,password,type_user FROM user ORDER BY type_user, login
After the ORDER BY operator, we would write the names of the fields and the sorting type (DESC or ASC).
SELECT id,login,password,type_user FROM user ORDER BY type_user DESC, login ASC
Categories: