在CategoryID建索引
--用with(index=CategoryID索引)

解决方案 »

  1.   


    select * from (
    select top 10 [Title],[AddTime] from [NewS] 
    where [CategoryID]=6  and [Area]=@Area and [State]=1 order by [Id] desc)t1
    union all
    select * from (
    select top 10 [Title],[AddTime] from [NewS] 
    where [CategoryID]=7  and [Area]=@Area and [State]=1 order by [Id] desc)t2这样会快点不?
      

  2.   

    需要查詢執行計劃有沒有用到CategoryID的索引
      

  3.   

    Union好像只对索引列有效。
    而且三楼的不对哦。还有没有其他办法
      

  4.   


    不会快. 还不如or或IN呢.
      

  5.   

    select [t2.Title],[t2.AddTime] from
    (select 6 as CategoryID
     union
     select 7 as CategoryID) as t1
    cross join [NewS] t2
    on (t1.CategoryID=t2.CategoryID) 
      

  6.   

    select [t2.Title],[t2.AddTime] from
    (select 6 as CategoryID
     union
     select 7 as CategoryID) as t1
    cross join [NewS] t2
    on (t1.CategoryID=t2.CategoryID) 
      

  7.   

    语句没啥好优化的了。
    把or改成union all的写法,并不能提高效率。
    在索引利用上做文章