INNER JOIN vs INNER JOIN (SELECT . FROM)

后端 未结 4 1760
栀梦
栀梦 2021-02-01 00:27

Is there any difference in terms of performance between these two versions of the same query?

--Version 1
SELECT p.Name, s.OrderQty
FROM Product p
INNER JOIN Sal         


        
4条回答
  •  盖世英雄少女心
    2021-02-01 01:02

    There won't be much difference. Howver version 2 is easier when you have some calculations, aggregations, etc that should be joined outside of it

    --Version 2 
    SELECT p.Name, s.OrderQty 
    FROM Product p 
    INNER JOIN 
    (SELECT ProductID, SUM(OrderQty) as OrderQty FROM SalesOrderDetail GROUP BY ProductID
    HAVING SUM(OrderQty) >1000) s 
    on p.ProductID = s.ProdctId 
    

提交回复
热议问题