当前位置: 代码迷 >> Sql Server >> Union 异常
  详细解决方案

Union 异常

热度:268   发布时间:2016-04-27 14:57:39.0
Union 错误

SELECT TOP 10 Title FROM artitle WHERE Title like '%aaa%' ORDER BY addtime DESC 

UNION 

SELECT TOP 10 Title FROM artitle WHERE Title like '%bbb%' ORDER BY addTime DESC



------解决方案--------------------
SQL code
--测试数据declare @artitle table (Title varchar(4),addtime datetime)insert into @artitleselect 'aaa1','2010-09-09' union allselect 'aaa2','2010-09-05' union allselect 'bbb1','2010-09-01' union allselect 'bbb3','2010-09-02' union allselect 'ccc1','2010-09-04' union allselect 'ccc4','2010-09-05'select * from (SELECT TOP 10 Title FROM @artitle WHERE Title like '%aaa%' ORDER BY addTime DESC) aaunionselect * from (SELECT TOP 10 Title FROM @artitle WHERE Title like '%bbb%' ORDER BY addTime DESC) bb/*Title-----aaa1aaa2bbb1bbb3*/