当前位置:网站首页>MySQL join skills
MySQL join skills
2022-07-28 06:29:00 【Strange patron saint】
The cartesian product :CROSS JOIN
Understand all kinds of JOIN First of all, we need to understand Cartesian product . Cartesian product is to A Each record in the table is related to B Each record of the table is forcibly put together . therefore , If A Table has n Bar record ,B Table has m Bar record , The result of the Cartesian product will be n*m Bar record . The following example ,t_blog Yes 10 Bar record ,t_type Yes 5 Bar record , All their Cartesian products have 50 Bar record . There are five ways to produce Cartesian product .
Internal connection :INNER JOIN
Internal connection INNER JOIN Is the most commonly used connection operation . From a mathematical point of view, it is to find the intersection of two tables , From the perspective of Cartesian product, it is to pick out ON Record with Clause condition . Yes INNER JOIN,WHERE( Equivalent connection ),STRAIGHT_JOIN,JOIN( Omit INNER) Four ways of writing . As for which kind of good I will be MySQL Of JOIN( Two ): Optimized narration . Examples are as follows .
Left connection :LEFT JOIN
Left connection LEFT JOIN It means to find the intersection of two tables plus the remaining data in the left table . Still from the Cartesian product point of view , That is to pick out... From Cartesian product first ON Record with Clause condition , Then add the remaining records in the left table ( See the last three ).
The right connection :RIGHT JOIN
The same goes for right connection RIGHT JOIN Is to find the intersection of two tables plus the remaining data of the right table . Again, from the perspective of Cartesian product , Right join is to pick out... From Cartesian product ON Record with Clause condition , Then add the remaining records in the right table ( See the last one ).
External connection :OUTER JOIN
Outer connection is to find the union of two sets . From the perspective of Cartesian product, it is to pick out ON Record with Clause condition , Then add the remaining records in the left table , Finally, add the remaining records in the right table . in addition MySQL I won't support it OUTER JOIN, But we can do the result of left connection and right connection UNION Operation to achieve .
USING Clause
MySQL Middle link SQL In the sentence ,ON The syntax form of clause is :table1.column_name = table2.column_name. When the schema design uses the same naming style for the columns of the join table , You can use USING Grammar to simplify ON grammar , The format is :USING(column_name).
therefore ,USING The function of is equivalent to ON, The difference lies in USING Specify an attribute name to connect two tables , and ON Specify a condition . in addition ,SELECT * when ,USING Will be removed USING Specified column , and ON Can't . Examples are as follows .
Natural join :NATURE JOIN
Natural connection is USING A simplified version of the clause , It finds the same columns in the two tables as the join condition to join . There is a left natural connection , Right natural connection and ordinary natural connection . stay t_blog and t_type Example , The same columns of the two tables are id, So I'll take it id As a condition of connection .
In addition, be sure to distinguish between the following three sentences .
Natural join :SELECT * FROM t_blog NATURAL JOIN t_type;
The cartesian product :SELECT * FROM t_blog NATURA JOIN t_type;
The cartesian product :SELECT * FROM t_blog NATURE JOIN t_type;
边栏推荐
- mixup_ratio
- set_ false_ path
- ClickHouse 中的公共表表达式CTE
- Graduation thesis | how to write literature review
- A NOVEL DEEP PARALLEL TIME-SERIES RELATION NETWORK FOR FAULT DIAGNOSIS
- Distinguishing PCB quality by color is a joke in itself
- set_ case_ analysis
- PLC的整体认识
- IMS-FACNN(Improved Multi-Scale Convolution Neural Network integrated with a Feature Attention Mecha
- Example of frameset usage
猜你喜欢

I heard that you are also practicing when I interviewed several junior interns.

PyTorch 学习笔记 4 —— 自动计算梯度下降 AUTOGRAD

MATLAB signal processing

Triode design, understanding saturation, linear region and cut-off region

雷达成像 Matlab 仿真 3 —— 多目标检测

clickhouse聚合之探索聚合内部机制

Arduino reads the analog voltage_ How mq2 gas / smoke sensor works and its interface with Arduino

Detailed explanation of creepage distance and electrical clearance

毕业论文 | 文献综述应该怎么写

Analysis of MOSFET damage at the moment of power failure of isolated power supply
随机推荐
Bag of tricks training convolution network skills
Example of frameset usage
MATLAB signal processing
USB network native driver for esxi updated to support esxi7.0.1
How to pop up the message dialog box
Learning notes of hardware circuit design 1 -- temperature rise design
WebService error maximum message size quota for incoming messages (65536) has been exceeded
多个ics日历合并成单个ics日历
RS232 RS485 RS422 communication learning and notes
Hugging face 的问题记录 I
Pycharm2019设置编辑器主题和默认代码
Weight decay
Esxi on arm 10/22 update
低功耗设计-isolation cell
解决内存占用比应用进程占用高的问题
VS Code 基础配置与美化
Design and analysis of contactor coil control circuit
Install visual studio 2019 steps and vs2019 offline installation package on win7
How to use the bit error meter?
PyTorch 学习笔记 4 —— 自动计算梯度下降 AUTOGRAD
