Is it possible to order by multiple rows?
I want my users to be sorted by last_activity
, but at the same time, I want the users with pictures to appear before the ones without
Something like this:
SELECT some_cols FROM `prefix_users` WHERE (some conditions) ORDER BY last_activity, pic_set DESC;
After the ORDER BY keyword, add the name of the column by which you'd like to sort records first (in our example, salary). Then, after a comma, add the second column (in our example, last_name ). You can modify the sorting order (ascending or descending) separately for each column.
This sorts your MySQL table result in Ascending or Descending order according to the specified column. The default sorting order is Ascending which you can change using ASC or DESC . SELECT * FROM [table-name] ORDER BY [column-name1 ] [ASC|DESC] , [column-name2] [ASC|DESC],..
If you want to sort multiple columns specify all the columns by a comma. column1 DESC, column2 ASC; Here, the result is sorted by column1 in descending order first then, result is sorted by column2 in ascending order.
If you specify multiple columns, the result set is sorted by the first column and then that sorted result set is sorted by the second column, and so on. The columns that appear in the ORDER BY clause must correspond to either column in the select list or columns defined in the table specified in the FROM clause.
SELECT some_cols FROM prefix_users WHERE (some conditions) ORDER BY pic_set DESC, last_activity;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With