如何合并同一表中通过不同查询条件产生的结果集
如:
select top 10 * from Article where ClassID=1
select top 10 * from Article where ClassID=2
select top 10 * from Article where ClassID=3
要把这30条记录合并成一个结果集,该怎么做?SQL语句或存储过程都可以
[解决办法]
try
Select * From
(select top 10 * from Article where ClassID=1
Union All
select top 10 * from Article where ClassID=2
Union All
select top 10 * from Article where ClassID=3 ) A
[解决办法]
如上
如果忽略重复项
Select * From
(select top 10 * from Article where ClassID=1
Union
select top 10 * from Article where ClassID=2
Union
select top 10 * from Article where ClassID=3 ) A