读书人

这条语句要如何改。

发布时间: 2013-03-13 10:56:58 作者: rapoo

这条语句要怎么改。。。
select top 3 * from test where type='xz'order by NEWID()
union
select top 3 * from test where type='pd'order by NEWID()

我想合并这两个结果集

现在是
消息 156,级别 15,状态 1,第 3 行关键字 'union' 附近有语法错误。

要怎么改 。
[解决办法]
select * from a
union
select * from b
order by NEWID()


order by要放在最后,你可以把两条语句的结果插入到零时表,然后用union
[解决办法]

select * from(select top 3 * from test where type='xz'order by newid())t
union
select * from(select top 3 * from test where type='pd'order by newid())t

读书人网 >SQL Server

热点推荐