sql - MySQL special ORDER BY -


suppose have following table

name        | genre --------------------- book 1      | scifi book 2      | horror book 3      | scifi book 4      | romance book 5      | horror 

how can sort table above "genre" in sql following results. please note order. it's h s r, , not h r s. possible achieve without using union?

name        | genre ------------------------ book 2      | horror book 5      | horror book 1      | scifi book 3      | scifi book 4      | romance 

edit: there 3 genres.

you use field function customise sort order

select * `table` order field(`genre`, 'horror', 'scifi', 'horror'), `name`; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -