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
Post a Comment