NOT IN vs NOT EXISTS

前端 未结 11 1528
粉色の甜心
粉色の甜心 2020-11-21 12:08

Which of these queries is the faster?

NOT EXISTS:

SELECT ProductID, ProductName 
FROM Northwind..Products p
WHERE NOT EXISTS (
    SELECT 1 
    FROM         


        
11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-21 12:48

    Actually, I believe this would be the fastest:

    SELECT ProductID, ProductName 
        FROM Northwind..Products p  
              outer join Northwind..[Order Details] od on p.ProductId = od.ProductId)
    WHERE od.ProductId is null
    

提交回复
热议问题