SELECT * FROM [P_Label] WHERE SortID IN (SELECT SortID FROM [P_Sort] WHERE ShowLabel=1)

解决方案 »

  1.   

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

  2.   

    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
    )