The difference between where and having in mysql

1. First of all, let’s talk about the same point: where and having are followed by a conditional statement, which plays the role of conditional selection, similar to the if statement we generally use in programming.

2. In terms of execution order, where is executed before having. And having is often used with group by, but where cannot be used with group by. The execution order of the three is where>group by>having.

3. The most important difference: having can be used with aggregate functions such as count, sum, avg, max, min, etc., but where cannot, otherwise an error will be reported.



Author: Bo Punk
Link: https://www.zhihu.com/question/63039317/answer/1843525054
Source: Zhihu
Copyright belongs to the author. For commercial reprinting, please contact the author for authorization. For non-commercial reprinting, please indicate the source.

Guess you like

Origin blog.csdn.net/Brady74/article/details/117341478