mysql - Two ORDER BY clauses and a LIMIT -
this sorting: have table ids, names , ratings. want list 10 best items based on ratings, that's fine:
select id items order ratings desc limit 10 but here comes hard part: want list 10 best items based on ratings order them alphabetically. tried
select id items order ratings desc, names asc limit 10 and
select id items order names asc, ratings desc limit 10 but neither gives desired result.
you use subquery:
select * ( select id, names items order ratings desc limit 10 ) t order names edit: further explanation
your original query sorts ratings desc, , names -- sort names same ratings. if 2 items had same rating, you'd 2 sorted name. it's going sort records rating first, , name afterwards (within same ratings).
Comments
Post a Comment