如有以下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
|