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速度会快一些