当前位置:网站首页>Difference between on, where and having
Difference between on, where and having
2022-07-28 04:01:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I wish every programmer can learn more languages .
ON 、WHERE、HAVING Can filter data by limiting conditions , But their use is very different . Let's analyze the differences between the three .
1. ON and WHERE
All queries will generate an intermediate temporary report , The query result is obtained from the returned Temporary Report .ON and WHERE The difference between the following restrictions , It's mainly about the time when the constraints work ,ON Filter database records according to restrictions , Then produce a temporary table ; and WHERE After the production of the temporary watch , Filter the results from the temporary table according to the restrictions .
For the above reasons ,ON and WHERE The main differences are :
1) Return results : It's on the left ( Right outside ) Connecting ,ON Will return to the left table ( Right table ) All the records in ; and WHERE in , At this time, it is equivalent to inner join, Only records that meet the conditions will be returned ( Because it is filtered from the temporary table , Will filter out the ones that don't meet the conditions ). 2) Speed : because ON The constraints occurred earlier , The data set of the temporary table should be small , therefore ON Better than WHERE.
2. HAVING and WHERE
HAVING and WHERE The difference is also related to the time when the constraints work ,HAVING It is to filter the result after the result of aggregate function calculation , Query results only return qualified groups ,HAVING Not alone , Only now GROUP BY clause .; and WHERE It's filtering results before calculating , Suppose the aggregate function uses WHERE, Then the aggregate function only calculates that WHERE Clause constraints data , such as :
SELECT COUNT(id) FROM db_equip WHERE tb_equip_type = ‘2’;Count The result of the calculation is to first filter the device type as 2 My equipment , Then count the device type as 2 Number of types .
In use and function ,HAVING and WHERE There are the following differences :
1) HAVING Not alone , Only now GROUP BY In clause ;WHERE That is, we can SELECT And other clauses , Can also be with GROUP BY Clause collocation ,WHERE The priority of aggregate function is higher than that of aggregate function HAVING. 2) because WHERE Filter data before aggregating functions ,HAVING Filter the grouping after the calculation , therefore WHERE It's faster than HAVING The query speed is fast .
3. summary
ON、WHERE、HAVING The main difference is that the restrictive condition in its clause is caused by the time when it works ,ON It is to filter records according to conditions before producing temporary tables ,WHERE It is to filter data from the temporary table of production , and HAVING It refers to the data that meets the conditions in the temporary table , After calculating and grouping , adopt HAVING Restrict statement filter grouping , The return result is that HAVING Grouping restricted by clause .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/118060.html Link to the original text :https://javaforall.cn
边栏推荐
- un7.27:如何在idea中成功搭建若依框架项目?
- [untitled]
- xml文件使用及解析
- Which stock exchange has the lowest commission? Is it safe to open an account on your mobile phone
- Advanced Mathematics (Seventh Edition) Tongji University exercises 3-4 personal solutions (first 8 questions)
- CH340 RTS DTR引脚编程驱动OLED
- Regression - linear regression
- C语言力扣第45题之跳跃游戏 II。遍历跳跃
- 离职前一定要做好这7件事情,少一件都很麻烦。
- Appnium -- app automated test tool
猜你喜欢

数据挖掘-02
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

ServletContext、request、response

I did these three things before the interview, and the result was actually direct
![[MySQL database] index and transaction (often used in interview)](/img/14/fa96e1f9dd22a1294a2018785e10b6.png)
[MySQL database] index and transaction (often used in interview)

Ch340 RTS DTR pin programming drives OLED

21天,胖哥亲自带你玩转OAuth2

Simple and easy-to-use performance testing tools recommended

R notes mice

servlet使用
随机推荐
LeetCode_ 409_ Longest palindrome string
Chinese Remainder Theorem of X problem
基于SSM实现在线租房系统
What is interface testing and its testing process
Fourier series
静态博客搭建工具汇总
Greed 122. The best time to buy and sell stocks II
Advanced Mathematics (Seventh Edition) Tongji University exercises 3-4 personal solutions (first 8 questions)
Protocols in swift
R notes mice
Day08 redis的基础知识
Implementation of online rental system based on SSM
[MySQL database] index and transaction (often used in interview)
Do Netease and Baidu have their own tricks for seizing the beach AI learning machine?
[openvx] VX for basic use of objects_ distribution
[P4] solve the conflict between local file modification and library file
LeetCode 0140. 单词拆分 II
[openvx] VX for basic use of objects_ pyramid
【无标题】
Dynamic planning - 62. Different paths