不过UNION 本身就会去重复行,只要不用UNION ALL 而且选TOP 10 就好了
select top 5 *
from
(
select * from tb where querytext = '关键字'
union
select top 10 * as id from tb order by inputtime desc
) t
order by id,inputtime desc
select top 5 *
from
(
select *,1 as ID from tb where querytext = '关键字'
union
select top 5 *,2 as id from tb order by inputtime desc
) t
order by id,inputtime desc
if(5-sum(select count(*) from 表))>0
insert 表 select * from 表 where infoflag in (select top 5-sum(select count(*) from 表 order by inputtime desc ) )
不知道楼主是不是这个意思 `
逻辑关系讲得不太明白