日期:2014-05-18  浏览次数:20593 次

分数不多,求一简单语句的优化方案
SELECT   *   FROM   [P_Label]   WHERE   SortID   IN   (SELECT   SortID   FROM   [P_Sort]   WHERE   ShowLabel=1)

------解决方案--------------------
等价于
SELECT * FROM [P_Label]
WHERE exists (
select 1 from [P_Sort] WHERE ShowLabel=1 and [P_Label].SortID = [P_Sort].SortID
)

------解决方案--------------------
SELECT * FROM [P_Label]
WHERE exists (
select 1 from [P_Label] a
inner join [P_Sort] b
on a.SortID=b.SortID
where b.ShowLabel=1
)



------解决方案--------------------
用exists比用in速度会快一些