mysql how to order by user defined order/sort
say for a table
---------+----------
name | category
---------+----------
apple | 0
orange | 0
book | 1
notebook | 1
textboo | 1
phone | 2
How to order it in the following order of category ie category=1, category=0, category=2
to get the view as
---------+----------
name | category
---------+----------
book | 1
notebook | 1
textbook | 1
apple | 0
orange | 0
phone | 2
How do we write an sql for this?
Also better, if the statement can identify and sort desc based on the number of items on each category.
You want to do this:
Update
In the first answer, the order is fixed by category. When ordering by the number of items in category, you want to do this: