当前位置:网站首页>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;![]()
边栏推荐
- NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
- [popular science] basic knowledge of thermal design: heat dissipation analysis of 5g optical devices
- A application wakes up B should be a fast method
- 指针函数(基础)
- [untitled]
- 【虚幻引擎UE】运行和启动的区别,常见问题分析
- Pointer function (basic)
- SPI read / write flash principle + complete code
- Invalid bound statement (not found) in idea -- problem solving
- [thingsboard] how to replace the homepage logo
猜你喜欢

蛇形矩阵

Key review route of probability theory and mathematical statistics examination

【thingsboard】替换首页logo的方法

直播预告 | 容器服务 ACK 弹性预测最佳实践

Discussion on the dimension of confrontation subspace

windows下Redis-cluster集群搭建

TPG x AIDU | AI leading talent recruitment plan in progress!

函数(基本:参数,返回值)

Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery

Kwai, Tiktok, video number, battle content payment
随机推荐
Sequelize. JS and hasmany - belongsto vs hasmany in serialize js
After the deployment of web resources, the navigator cannot obtain the solution of mediadevices instance (navigator.mediadevices is undefined)
Study notes 7
How to carry out "small step reconstruction"?
函數(易錯)
windows下Redis-cluster集群搭建
How to remove installed elpa package
【科普】热设计基础知识:5G光器件之散热分析
Decimal to hexadecimal
Sequence diagram of single sign on Certification Center
PHP reads the INI file and writes the modified content
Fuel consumption calculator
File upload bypass summary (upload labs 21 customs clearance tutorial attached)
揭秘技术 Leader 必备的七大清奇脑回路
PHP读取ini文件并修改内容写入
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
Function (error prone)
web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
How can CIOs use business analysis to build business value?
【UNIAPP】系统热更新实现思路
