Which SQL statement is faster? (HAVING vs. WHERE…)

后端 未结 8 1582
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 20:18
SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU
    FROM  PRACOWNICY
    GROUP BY NR_DZIALU
    HAVING NR_DZIALU = 30

or

SE         


        
相关标签:
8条回答
  • 2020-12-02 20:47

    "WHERE" is faster than "HAVING"!

    The more complex grouping of the query is - the slower "HAVING" will perform to compare because: "HAVING" "filter" will deal with larger amount of results and its also being additional "filter" loop

    "HAVING" will also use more memory (RAM)

    Altho when working with small data - the difference is minor and can absolutely be ignored

    0 讨论(0)
  • 2020-12-02 20:50

    Both the statements will be having same performance as SQL Server is smart enough to parse both the same statements into a similar plan.

    So, it does not matter if you use WHERE or HAVING in your query.

    But, ideally you should use WHERE clause syntactically.

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