Select * from (select top 2 * from Customers where city='London' order by newid()) a
union
select * from (select top 3 * from Customers where city='Bern' order by newid()) b
union
select * from (select top 3 * from Customers where city='Bern' order by newid()) b
union all
select * from (select top 3 * from Customers where city='Bern' order by newid()) tem2
(select top 2 *,newid() as temp_id from syscolumns where name<>'London' order by newid()) a
union
select * from
(select top 3 *,newid() as temp_id from syscolumns where name<>'Bern' order by newid()) b
union all
select * from (select top 3 * from Customers where city='Bern' order by newid()) bb
union all
select coloumnlist (except newid) from (select top 3 *,newid() from Customers where city='Bern' order by newid()) tem2
otherwise your will get error message
如果语句中包含 UNION 运算符,那么 ORDER BY 子句中的项就必须出现在选择列表中
try:
select top 2 * into #temp from Customers where city='London' order by newid()
insert #temp select top 3 * from Customers where city='Bern' order by newid()
select * from #temp
drop table #temp