MySQL ordering results by specific field values
by Sasikumar[ Edit ] 2013-10-21 16:09:53
To order the values of a mysql result by a specific field value
We can use the following query
SELECT name, species FROM `pet` ORDER BY FIELD(species, 'dog','cat','snake','bird'), name ASC
Output:
Name | Species |
---|
Bowser | dog |
Buffy | dog |
Fang | dog |
Claws | cat |
Fluffy | cat |
Slim | snake |
Chirpy | bird |
Whistler | bird |