读书人

分数不多,求一简单语句的优化方案解决

发布时间: 2012-01-15 22:57:48 作者: rapoo

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

读书人网 >SQL Server

热点推荐