select [table],id,title,[time],[type] from
(
select top 100 percent 'mixTable1' as [table], id,title,[time],[type] from mixTable1 where title like '%刘%'
union all
select top 100 percent 'mixTable2' as [table], id ,title,[time],[type] from mixTable2 where title like '%刘%'
order by [time] desc
) ff
从结果看其中order by [time] desc没起作用
嗯,加入top 100 percent 后不会再报错,为什么单独运行
select top 100 percent 'mixTable1' as [table], id,title,[time],[type] from mixTable1 where title like '%刘%'
union all
select top 100 percent 'mixTable2' as [table], id ,title,[time],[type] from mixTable2 where title like '%刘%'
order by [time] desc
会排序,但运行上面的sql语句就不会排序了
不知道,我猜测是:sql在union两个结果集的时候是乱序拼接的