select union 查询出来的结果,如何按指定顺序输出

如有以下sql语句:

select name from student where id='1003' union all
select name from student where id='1001' union all
select name from student where id='1004'

查询出来的结果顺序是未知的。

现在必须按照一定的顺序显示查询的结果,可以用这样的方法:

select name from (
select name ,2 flag from student where id='1003' union all
select name ,1 flag from student where id='1001' union all
select name ,3 flag from student where id='1004') tem order by flag
posted @ 2011-05-12 10:16  瓜蛋  阅读(5860)  评论(0编辑  收藏  举报