当前位置:网站首页>Mysql database easy learning 09 - commonly used by data analysts: multi table query of data query language DQL
Mysql database easy learning 09 - commonly used by data analysts: multi table query of data query language DQL
2022-06-22 01:58:00 【Smart Aries】
1 The relationship between tables
1.1 one-on-one

1.2 One to many

1.3 Many to many

2 How to connect
2.1 Transverse connection
2.1.1 Internal connection inner join
Connect two tables according to the connection conditions , Return the line that meets the condition 
select Field 1[,…] from surface 1[ inner] join surface 2 on Connection condition ;
2.1.2 Left connection left join
In addition to the lines that satisfy the join conditions, the result , It also includes all the rows of the left table 
select Field 1[,…] from surface 1 left join surface 2 on Connection condition ;
2.1.3 The right connection right join
In addition to the lines that satisfy the join conditions, the result , It also includes all the rows of the right table 
select Field 1[,…] from surface 1 right join surface 2 on Connection condition ;
2.1.4 The cartesian product cross join
Suppose the set A={a,b}, aggregate B={1,2,3}, Then the Cartesian product of two sets is {(a,1),(a,2),(a,3),(b,1),(b,2),(b,3)}
select Field 1[,…] from surface 1, surface 2[,…];
select Field 1[,…] from surface 1 cross join surface 2[,…];
Eliminate Cartesian product :
Line by line judgment , Equal leave , Unequal exclusion
select Field 1[,…] from surface 1, surface 2[,…] where filter ;
2.1.5 Self join
By setting the table alias , Virtualize the same table into multiple tables for connection
select * from tabel a inner join table b
on a.id = b.id
2.2 Longitudinal connection
2.2.1 Concept
Put more than one select The query results of the statement are combined into a result set
Of the merged result set Number of columns 、 Sequence and data type It has to be exactly the same
2.2.2 union duplicate removal :
#select Field 1[, Field 2,…] from Table name union select Field 1[, Field 2,…] from Table name ;
select * from t1 union select * from t2;
2.2.3 union all No weight removal :
#select Field 1[, Field 2,…] from Table name union all select Field 1[, Field 2,…] from Table name ;
select * from t1 union all select * from t2;
3 Connection condition
3.1 Equivalent connection
surface 1.id= surface 2.id
3.2 Unequal value connection
surface 1.id Compare surface 2.id
边栏推荐
- BSV上的委托合约
- Mathematical knowledge of Sinorgchem in the first round of noip preliminary csp-j1 csp-s1 (I)
- Shardingsphere-proxy-5.0.0 implementation of distributed hash modulo fragmentation (4)
- 初识Unity3D(项目结构、ProBuilder第三方插件)
- How to judge whether a man will be rich or poor in the future?
- 数电期末笔记
- 英特尔笔试题小整理DIY
- Individual problem solution of the 298th round of force deduction
- Mba-day24 best value problem
- MBA-day24 最值问题
猜你喜欢

IE浏览器自动跳转edge怎么恢复

【第 15 章 基于小波的图像压缩技术深度学习机器学习的图像处理应用matlab.】

Farm Game

How to restore the IE browser auto jump edge

DAST 黑盒漏洞扫描器 第四篇:扫描性能

机器学习编译第1讲:机器学习编译概述
![[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]](/img/2f/b2f141bf2f0b1f2f80444d37529a9b.png)
[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]

Pyechart drawing word cloud

ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)

基于DPDK的高效包处理系统
随机推荐
Five strokes first lesson fingering
NVIDIA written interview questions sorting DIY
Five years after graduation, I finally became a software testing engineer with a monthly salary of 13000
测试apk-异常管控Sensor攻击者开发
【第 04 章 基于Hough变化的答题卡识别】
【英伟达发展历程纪实618-01】
Scuba China trip - Suzhou station, online and offline limited time registration channel has been opened!
Individual problem solution of the 298th round of force deduction
LocalDateTime格式化时间
Recommended by Ali, Tencent and Baidu software testing engineers - waterfall model of software testing model
[chapter 04 answer sheet recognition based on Hough change]
数字信号处理
联发科技 --联发科技简介++附上笔经面经
IE浏览器自动跳转edge怎么恢复
Mba-day18 elimination method
Copy in pytorch_ Summary of differences between (), detach (), data (), and clone () operations
[chapter 02 weight adaptive image denoising technology based on Morphology - full system matlab intelligent driving in-depth learning]
Mathematical knowledge in the first round of noip preliminary round csp-j1 csp-s1 Xinjiang Olympic Games (II)
Lianfa science and technology -- Introduction to Lianfa science and technology ++ attached
数电期末笔记