当前位置:网站首页>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;
边栏推荐
- Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
- All in one 1413: determine base
- 首席信息官如何利用业务分析构建业务价值?
- File upload bypass summary (upload labs 21 customs clearance tutorial attached)
- Network security - record web vulnerability fixes
- Leetcode hot topic Hot 100 day 33: "subset"
- mxnet导入报各种libcudart*.so、 libcuda*.so找不到
- Here comes the Lantern Festival red envelope!
- Study notes 7
- 直播预告 | 容器服务 ACK 弹性预测最佳实践
猜你喜欢
File upload bypass summary (upload labs 21 customs clearance tutorial attached)
揭秘技术 Leader 必备的七大清奇脑回路
[phantom engine UE] package error appears! Solutions to findpin errors
Managed service network: application architecture evolution in the cloud native Era
windows下Redis-cluster集群搭建
Burpsuite grabs app packets
函数(基本:参数,返回值)
首席信息官如何利用业务分析构建业务价值?
如何优雅的获取每个分组的前几条数据
概率论与数理统计考试重点复习路线
随机推荐
Managed service network: application architecture evolution in the cloud native Era
Here comes the Lantern Festival red envelope!
Reading and visualization of DICOM, MHD and raw files in medical imaging
level18
[phantom engine UE] package error appears! Solutions to findpin errors
Decimal to hexadecimal
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)
About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
The remainder operation is a hash function
Components in protective circuit
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
【UNIAPP】系统热更新实现思路
MacBook installation postgresql+postgis
揭秘技术 Leader 必备的七大清奇脑回路
【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
Sword finger offer 04 Search in two-dimensional array
Study notes 7
Wenet: E2E speech recognition tool for industrial implementation
2022-2028 global and Chinese virtual data storage Market Research Report
Chapter 6 text processing tools for shell programming (awk)