Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple level ordering

I have a table with some records with fields like name, rating etc.

I first want to sort based on rating limiting results to 20 and then on this resultset want to further apply sort based on name.

I know to sort we need to use the query like

Select * from table order by rating Desc limit 20 

but on this resultset how to apply another level of ordering? How can I combine these two sorts in one sqlite statement?

like image 265
Sapan Avatar asked Apr 21 '11 09:04

Sapan


People also ask

What does multiple level sorting mean?

Multi-Level Data Sorting is the process of arranging the data of more than one column in ascending or descending order.

What's the advantage of multi-level sort versus single level sort?

Combining multiple fields in one sort is called multilevel sorting. Multilevel sorting can help clarify search results while also increasing their accuracy.

Can you change the order of a multi-level sort?

If you need to change the order of a multilevel sort, it's easy to control which column is sorted first. Simply select the desired column, then click the Move Up or Move Down arrow to adjust its priority.


1 Answers

You could use e.g. ORDER BY rating DESC, name ASC to sort by rating and then, if the ratings are equal, by name.

like image 122
ThiefMaster Avatar answered Oct 11 '22 06:10

ThiefMaster