SQL Efficiency: WHERE IN Subquery vs. JOIN then GROUP

后端 未结 7 1648
予麋鹿
予麋鹿 2021-02-07 09:35

As an example, I want to get the list of all items with certain tags applied to them. I could do either of the following:

SELECT Item.ID, Item.Name
FROM Item
WH         


        
相关标签:
7条回答
  • 2021-02-07 10:09

    Performance always seems to get the vote, but you also hear "it is cheaper to buy hardware than programmers"

    The second wins on performance.

    Sometimes it is nice to look at SQL and know the purpose, but that's what comments are for. The first query is using the other table for a filter - pretty straight forward.

    The second one would make more sense (from an understanding purpose and not performance) using distinct instead of group by. I would expect some aggregates to be in the select, but there aren't any. Speed kills.

    0 讨论(0)
提交回复
热议问题