MySQL double sort

I would like to double my list of users. Is this possible in a single MySQL query?

  • Sort by activity
  • Sort by ID

For instance:

 1 Jack Active 2 Jill Active 5 Jens Active 3 Harry Inactive 4 Larry Inactive 6 Luke Inactive 
+6
source share
5 answers

You can use the ORDER BY to sort as many columns as possible.

 SELECT id, name, activity FROM userList ORDER BY Activity, ID 

I would suggest reading the MySQL ORDER BY docs. You can sort the data in ASC or DESC order: MySQL: ORDER optimization

+8
source
 SELECT id, name, activity FROM your_table ORDER BY activity ASC, id ASC 
+4
source
 Select * from table order by activity, ID; 
+1
source
 SELECT * FROM table_name ORDER BY activity, ID; 
+1
source

Yes,

 SELECT (user.name|| ' ' || user.status) AS sorted_list FROM STUDENTS ORDER BY user.status, user.name 
0
source

Source: https://habr.com/ru/post/913546/


All Articles