`

[Teach Youself SQL in 10 Minutes] The difference between HAVING and WHERE

    博客分类:
  • db
 
阅读更多

 

The difference between HAVING and WHERE Here's another way to look it: WHERE filters before data is grouped, and HAVING filters after data is grouped. This is an important distinction; rows that are eliminated by a WHERE clause will not be included in the group. This could change the calculated values which in turn could affect which groups are filtered based on the use of those values in the HAVING clause.

 

 

Using HAVING and WHERE HAVING is so similar to WHERE that most DBMSs treat them as the same thing if no GROUP BY is specified. Nevertheless, you should make that distinction yourself. Use HAVING only in conjunction with GROUP BY clauses. Use WHERE for standard row-level filtering.

 

 

BTW:

The only difference is that WHERE filters rows and HAVING filters groups.

The difference between HAVING and WHERE Here's another way to look it: WHERE filters before data is grouped, and HAVING filters after data is grouped.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics