I'm pulling the top 15 locations from the database by sorting based on the usedby column, a running total of how many reco开发者_如何学Pythonrds use that location. The problem is, this returns them sorted by usedby when I'd really like to sort them alphabetically by the name column. I'm thinking this might require some sort of subquery?
SELECT * FROM `location` ORDER BY `usedby` DESC LIMIT 0, 15
Summary: Need to return the above SQL result sorted by the name
column.
As you suspected, this can be done with a subquery:
SELECT sq.* FROM (
SELECT loc.* FROM `location` as loc ORDER BY loc.usedby DESC LIMIT 0, 15
) as sq ORDER BY sq.name
精彩评论