当前位置:网站首页>SQL set operation
SQL set operation
2022-07-05 04:34:00 【Xiao Wang next door to you】
Written above
- Author's brief introduction : Hello everyone , I'm Xiao Wang *️
- Personal home page : Xiao Wang next door to you
- Welcome to thumb up + Collection ️+ Leaving a message.
- special column :SQL*️
*️ If you have something you don't understand in the process of learning , Welcome to the comment area to leave a message and ask questions ! I hope I can make progress with you , Grow up together !
Catalog
The addition and subtraction of tables
Select the common part of the table —— INTERSECT
Recorded subtraction —— EXCEPT
The addition and subtraction of tables
What is set operation
- Sets represent... In the field of mathematics “( All kinds of ) The sum of things ”, Represents a collection of records in the database domain .
Addition of tables —— UNION
- surface 1
surface 2
You can see the watch 1 Of 004、5、7、8 In the table 2 There is no such thing as , At the same time in the table 2 Medium 9、10 In the table 1 It doesn't exist in the world
SELECT product_id, product_name FROM Product UNION SELECT product_id, product_name FROM Product2;
You can see union Is to find the union , And the weight is automatically removed , The set operator removes duplicate records .
If we want to keep duplicate lines, we just need to Add ALL that will do
You can see that the repeated lines have been saved
Precautions for set operation
- The number of columns of the record as the operands must be the same
- The type of the column in the record as the operation object must be consistent
- You can use any SELECT sentence , but ORDER BY Clause can only be used last time
Select the common part of the table —— INTERSECT
- Select the common part of the two record sets INTERSECT ( intersection )
SELECT product_id, product_name FROM Product INTERSECT SELECT product_id, product_name FROM Product2 ORDER BY product_id;
You can see INSTERSECT Is to find the intersection of two records (PS:MYSQL Not available in INSTERSECT)
Recorded subtraction —— EXCEPT
- Subtraction EXCEPT ( Difference set )(PS: Only Oracle Don't use EXCEPT , and
Is to use its unique MINUS Operator . Use Oracle Users of , Please use MINUS
Instead of EXCEPT . Besides ,MySQL Not yet EXCEPT , So it can't be used .)SELECT product_id, product_name FROM Product EXCEPT SELECT product_id, product_name FROM Product2 ORDER BY product_id;
![]()
边栏推荐
- SPI read / write flash principle + complete code
- 概率论与数理统计考试重点复习路线
- Bit operation skills
- [phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)
- PHP读取ini文件并修改内容写入
- Chapter 6 text processing tools for shell programming (awk)
- [crampon game] MC tutorial - first day of survival
- Uncover the seven quirky brain circuits necessary for technology leaders
- How to remove installed elpa package
- Machine learning decision tree
猜你喜欢
Function (error prone)
[PCL self study: feature9] global aligned spatial distribution (GASD) descriptor (continuously updated)
windows下Redis-cluster集群搭建
C26451: arithmetic overflow: use the operator * on a 4-byte value, and then convert the result to an 8-byte value. To avoid overflow, cast the value to wide type before calling the operator * (io.2)
windows下Redis-cluster集群搭建
Setting up redis cluster cluster under Windows
【虚幻引擎UE】运行和启动的区别,常见问题分析
防护电路中的元器件
2022-2028 global and Chinese video coding and transcoding Market Research Report
Uncover the seven quirky brain circuits necessary for technology leaders
随机推荐
[uniapp] system hot update implementation ideas
This is an age of uncertainty
Study notes 7
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
网络安全-记录web漏洞修复
mxnet导入报各种libcudart*.so、 libcuda*.so找不到
Neural networks and deep learning Chapter 4: feedforward neural networks reading questions
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
All in one 1413: determine base
Raki's notes on reading paper: code and named entity recognition in stackoverflow
Label exchange experiment
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
A survey of automatic speech recognition (ASR) research
How can CIOs use business analysis to build business value?
English topic assignment (26)
【科普】热设计基础知识:5G光器件之散热分析
WeNet:面向工业落地的E2E语音识别工具
线上故障突突突?如何紧急诊断、排查与恢复
Sequence diagram of single sign on Certification Center