/ Published in: MySQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
+----------+--------+---------------------+ | fruit_id | name | variety | +----------+--------+---------------------+ | 11 | Banana | Burro | | 12 | Banana | Cavendish | | 10 | Banana | Plantain | | 6 | Apple | Cox's Orange Pippin | | 7 | Apple | Granny Smith | | 1 | Apple | Red Delicious | | 8 | Pear | Anjou | | 4 | Pear | Bartlett | | 2 | Pear | Comice | | 5 | Orange | Blood | | 3 | Orange | Navel | | 9 | Orange | Valencia | +----------+--------+---------------------+ SELECT * FROM fruit ORDER BY FIELD(name, 'Banana', 'Apple') DESC, variety; +----------+--------+---------------------+ | fruit_id | name | variety | +----------+--------+---------------------+ | 6 | Apple | Cox's Orange Pippin | | 7 | Apple | Granny Smith | | 1 | Apple | Red Delicious | | 11 | Banana | Burro | | 12 | Banana | Cavendish | | 10 | Banana | Plantain | | 8 | Pear | Anjou | | 4 | Pear | Bartlett | | 5 | Orange | Blood | | 2 | Pear | Comice | | 3 | Orange | Navel | | 9 | Orange | Valencia | +----------+--------+---------------------+ +----------+--------+---------------------+ | fruit_id | name | variety | +----------+--------+---------------------+ | 11 | Banana | Burro | | 12 | Banana | Cavendish | | 10 | Banana | Plantain | | 6 | Apple | Cox's Orange Pippin | | 7 | Apple | Granny Smith | | 1 | Apple | Red Delicious | | 5 | Orange | Blood | | 3 | Orange | Navel | | 9 | Orange | Valencia | | 8 | Pear | Anjou | | 4 | Pear | Bartlett | | 2 | Pear | Comice | +----------+--------+---------------------+
URL: http://www.electrictoolbox.com/mysql-order-specific-field-values/