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?

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.


This query should do the trick:

SELECT * FROM (SELECT * FROM table ORDER BY rating DESC LIMIT 20) ORDER BY name

Need Your Help

Best way for interprocess communication in C++

c++ memory boost ipc shared

I have two processes one will query other for data.There will be huge amount of queries in a limited time (10000 per second) and data (>100 mb) will be transferred per second.Type of data will be an

Hibernate-sequence doesn't exist

java spring hibernate

I tried to upgrade hibernate from 4 to 5 in my project with spring 4.2 version. After this upgrade, I found the following error in my stack trace when I called a method for updating.