当前位置:网站首页>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;
边栏推荐
- What about the insufficient memory of Clickhouse aggregation? Then improve the polymerization performance
- Chinese display problem of calendarextender control
- Learning notes of hardware circuit design 1 -- temperature rise design
- Communication between DSP and FPGA
- 机器学习笔记 5 —— Logistic Regression
- Cronbach’s α?KMO系数?因子载荷?史上最易懂的问卷信效度分析教程!!!(SPSS和AMOS)
- Electric fast burst (EFT) design - EMC series hardware design notes 4
- set_ case_ analysis
- PyTorch 学习笔记 2 —— About Tensor
- Perl入门学习(十一)文件操作
猜你喜欢

What is the AEM testpro cv100 and fluke dsx-8000 of category 8 network cable tester?

Bert bidirectional encoder based on transformer

ICC2(三)Clock Tree Synthesis

基于 YOLOV5 的 SAR 图像舰船检测

ConNeXt

Surge impact immunity experiment (surge) -emc series Hardware Design Notes 6

A NOVEL DEEP PARALLEL TIME-SERIES RELATION NETWORK FOR FAULT DIAGNOSIS

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

How to test industrial Ethernet cables (using fluke dsx-8000)?

Communication between DSP and FPGA
随机推荐
Vs code basic configuration and beautification
mysql join技巧
雷达成像 Matlab 仿真 4 —— 距离分辨率分析
Chinese display problem of calendarextender control
Shuffle Net_ v1-shuffle_ v2
set_case_analysis
ASP. Net read database bound to treeview recursive mode
Word自动目录字体修改和行间距的问题
Monitor the CPU temperature of raspberry pie 4B installed with esxi on ARM
For a large amount of data, matlab generates Excel files and typesetting processing source code
How can fluke dsx2-5000 and dsx2-8000 modules find the calibration expiration date?
set_multicycle_path
多个ics日历合并成单个ics日历
What about the insufficient memory of Clickhouse aggregation? Then improve the polymerization performance
Overall understanding of PLC
ICC2使用report_placement检查floorplan
【YOLOv5】环境搭建:Win11 + mx450
Synopsys Multivoltage Flow
Perl入门学习(十一)文件操作
初学者进行传感器选型
