分数不多,求一简单语句的优化方案
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速度会快一些