mysql - sql union order -


i have table students names , heights. want query order students higher 150cm alphabetically , students smaller 150cm in descending order of names.

something this:

(select * students height >= 150 order name)   union  (select * students height < 150 order name desc) 

it's not working because union mess order of rows in subqueries. know it's normal, union output set , in set order it's not important. there append?

   select *    students    order if(height >= 150, 1,0 ) desc,              if(height >= 150, name, '') asc,              name desc 

sample output

+------+--------+ | name | height | +------+--------+ |    |    189 | | m    |    666 | | thy  |    166 | | yyy  |   1277 | | zz   |    101 | | swq  |    122 | | n    |    111 | | g    |    145 | +------+--------+ 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -