SQL: WHERE vs HAVING Clause
🧵👇
🧵👇
3. With GROUP BY
- If HAVING is used in GROUP BY query, then it will filter the aggregated results at the end, after GROUP BY is executed
- While WHEN will be executed before GROUP BY, it will filter the record before GROUP BY
- If HAVING is used in GROUP BY query, then it will filter the aggregated results at the end, after GROUP BY is executed
- While WHEN will be executed before GROUP BY, it will filter the record before GROUP BY
4. Conclusion
- The HAVING clause should be only used with the GROUP BY clause, other than that we should always use the WHERE clause for filtering, as it uses Indexing
- WHERE is always executed before GROUP BY, and HAVING is executed afterwards
- The HAVING clause should be only used with the GROUP BY clause, other than that we should always use the WHERE clause for filtering, as it uses Indexing
- WHERE is always executed before GROUP BY, and HAVING is executed afterwards
Thanks for staying till the end!
Before you go, do you know?
I've also started writing on LinkedIn.
I share some exclusive content there, which I never share here.
Follow me on Linkedin to stay updated with Backend content:
linkedin.com
Before you go, do you know?
I've also started writing on LinkedIn.
I share some exclusive content there, which I never share here.
Follow me on Linkedin to stay updated with Backend content:
linkedin.com
Namaste, I'm Vikas!
Every Mon, Wed & Friday - I tweet a thread on Backend Development. Follow me @vikasrajputin to read all my future threads.
Like and RT the first tweet below to support my work.
Every Mon, Wed & Friday - I tweet a thread on Backend Development. Follow me @vikasrajputin to read all my future threads.
Like and RT the first tweet below to support my work.
جاري تحميل الاقتراحات...