[{"data":1,"prerenderedAt":112},["ShallowReactive",2],{"term-h\u002Fhaving":3,"related-h\u002Fhaving":101},{"id":4,"title":5,"acronym":6,"body":7,"category":83,"description":84,"difficulty":85,"extension":86,"letter":87,"meta":88,"navigation":89,"path":90,"related":91,"seo":95,"sitemap":96,"stem":99,"subcategory":6,"__hash__":100},"terms\u002Fterms\u002Fh\u002Fhaving.md","HAVING",null,{"type":8,"value":9,"toc":77},"minimark",[10,15,19,23,26,30,66,70,73],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"HAVING is like WHERE but it filters after GROUP BY aggregation. WHERE filters rows before grouping, HAVING filters groups after. 'Show me users who have made MORE than 5 orders' — that is a HAVING job.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"HAVING filters the results of GROUP BY aggregations. Because WHERE is evaluated before aggregation, it cannot filter on aggregate values like COUNT(*) or SUM(). HAVING is evaluated after GROUP BY and can reference aggregate functions in its conditions.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-sql shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","SELECT user_id, COUNT(*) AS order_count\nFROM orders\nGROUP BY user_id\nHAVING COUNT(*) > 5;  -- Can't use WHERE here\n","sql","",[38,39,40,48,54,60],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"SELECT user_id, COUNT(*) AS order_count\n",[41,49,51],{"class":43,"line":50},2,[41,52,53],{},"FROM orders\n",[41,55,57],{"class":43,"line":56},3,[41,58,59],{},"GROUP BY user_id\n",[41,61,63],{"class":43,"line":62},4,[41,64,65],{},"HAVING COUNT(*) > 5;  -- Can't use WHERE here\n",[11,67,69],{"id":68},"when-youll-hear-this","When You'll Hear This",[16,71,72],{},"\"Use HAVING to filter groups, not WHERE.\" \u002F \"HAVING COUNT(*) > 0 to exclude empty groups.\"",[74,75,76],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":50,"depth":50,"links":78},[79,80,81,82],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":68,"depth":50,"text":69},"database","HAVING is like WHERE but it filters after GROUP BY aggregation. WHERE filters rows before grouping, HAVING filters groups after.","intermediate","md","h",{},true,"\u002Fterms\u002Fh\u002Fhaving",[92,93,94],"GROUP BY","WHERE","SELECT",{"title":5,"description":84},{"changefreq":97,"priority":98},"weekly",0.7,"terms\u002Fh\u002Fhaving","3rb5Qt5usxiFtpkqBBimjdqq4E1erwH4d30X70GwH0g",[102,105,109],{"title":92,"path":103,"acronym":6,"category":83,"difficulty":85,"description":104},"\u002Fterms\u002Fg\u002Fgroup-by","GROUP BY collapses rows with the same value into one group so you can count, sum, or average them. 'How many orders per user?' — GROUP BY user_id.",{"title":94,"path":106,"acronym":6,"category":83,"difficulty":107,"description":108},"\u002Fterms\u002Fs\u002Fselect","beginner","SELECT is how you ask a database to give you data. It is the 'Read' in CRUD.",{"title":93,"path":110,"acronym":6,"category":83,"difficulty":107,"description":111},"\u002Fterms\u002Fw\u002Fwhere","WHERE is how you filter which rows a query affects. Without WHERE, SELECT returns everything, UPDATE changes everything, DELETE deletes everything.",1776518285582]