当前位置:网站首页>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;![]()
边栏推荐
- [moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)
- 取余操作是一个哈希函数
- Neural networks and deep learning Chapter 2: machine learning overview reading questions
- Basic analysis of IIC SPI protocol
- Bit operation skills
- 程序员应该怎么学数学
- Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 006 unity toolbar
- PHP reads the INI file and writes the modified content
- Leetcode hot topic Hot 100 day 33: "subset"
- FFmepg使用指南
猜你喜欢

【虚幻引擎UE】运行和启动的区别,常见问题分析

Invalid bound statement (not found) in idea -- problem solving

Web开发人员应该养成的10个编程习惯

CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1

【科普】热设计基础知识:5G光器件之散热分析

【UNIAPP】系统热更新实现思路

Raki's notes on reading paper: code and named entity recognition in stackoverflow

2022-2028 global and Chinese equipment as a Service Market Research Report

美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败

2022-2028 global and Chinese video coding and transcoding Market Research Report
随机推荐
What are the building energy-saving software
A application wakes up B should be a fast method
托管式服务网络:云原生时代的应用体系架构进化
防护电路中的元器件
You Li takes you to talk about C language 7 (define constants and macros)
Reading and visualization of DICOM, MHD and raw files in medical imaging
Function (basic: parameter, return value)
NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
CUDA Programming atomic operation atomicadd reports error err:msb3721, return code 1
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
Decimal to hexadecimal
All in one 1413: determine base
Cookie learning diary 1
Chapter 6 text processing tools for shell programming (awk)
A solution to the problem that variables cannot change dynamically when debugging in keil5
How to force activerecord to reload a class- How do I force ActiveRecord to reload a class?
Setting up redis cluster cluster under Windows
Sword finger offer 07 Rebuild binary tree
美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败
Here comes the Lantern Festival red envelope!
