当前位置:网站首页>Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询
Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询
2022-06-22 01:34:00 【潇洒白羊】
1 表之间的关系
1.1 一对一

1.2 一对多

1.3 多对多

2 连接方式
2.1 横向连接
2.1.1 内连接 inner join
按照连接条件连接两个表,返回满足条件的行
select 字段1[,…] from 表1[ inner] join 表2 on 连接条件;
2.1.2 左连接 left join
结果中除了包括满足连接条件的行外,还包括左表的所有行
select 字段1[,…] from 表1 left join 表2 on 连接条件;
2.1.3 右连接 right join
结果中除了包括满足连接条件的行外,还包括右表的所有行
select 字段1[,…] from 表1 right join 表2 on 连接条件;
2.1.4 笛卡尔积 cross join
假设集合A={a,b},集合B={1,2,3},则两个集合的笛卡尔积为{(a,1),(a,2),(a,3),(b,1),(b,2),(b,3)}
select 字段1[,…] from 表1,表2[,…];
select 字段1[,…] from 表1 cross join 表2[,…];
消除笛卡尔积:
逐行判断,相等的留下,不相等的排除
select 字段1[,…] from 表1,表2[,…] where 筛选条件;
2.1.5 自连接
通过设置表别名,将同一张表虚拟为多张表进行连接
select * from tabel a inner join table b
on a.id = b.id
2.2 纵向连接
2.2.1 概念
把多条select语句的查询结果合并为一个结果集
被合并的结果集的列数、顺序和数据类型必须完全一致
2.2.2 union去重:
#select 字段1[,字段2,…] from 表名 union select 字段1[,字段2,…] from 表名;
select * from t1 union select * from t2;
2.2.3 union all不去重:
#select 字段1[,字段2,…] from 表名 union all select 字段1[,字段2,…] from 表名;
select * from t1 union all select * from t2;
3 连接条件
3.1 等值连接
表1.id=表2.id
3.2 不等值连接
表1.id 比较 表2.id
边栏推荐
- 数学知识复习:三重积分
- 【第 26 章 基于最小误差法和区域生长的医学影响分割系统--matlab深度学习实战GUI项目】
- Audio and video learning route and learning materials recommendation
- acwing 837. Number of points in connected blocks (additional information maintained by querying sets - number of sets)
- Heidisql always makes errors when inserting data. What should I do
- LeetCode+ 46 - 50
- 第 24 章 基于 Simulink 进行图像和视频处理--matlab深度学习实战整理
- 求一个防关联检测工具,浏览器指纹在线检测
- 【第 04 章 基于Hough变化的答题卡识别】
- 光照相关 shader
猜你喜欢

ASEMI肖特基二极管1N5819参数,1N5819代换,1N5819货源

【第 17 章 基于 Harris 的角点特征检测--Matlab机器学习项目实战】

acwing 835. Trie string statistics

2022年中国手机银行年度专题分析

【第 26 章 基于最小误差法和区域生长的医学影响分割系统--matlab深度学习实战GUI项目】

The Sandbox 与《时代周刊》达成合作,在元宇宙建立“纽约时报广场”

DAST black box vulnerability scanner part 4: scanning performance

出现UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0xe9 in position 0: ordinal not in range解决方法

Farm Game

Commission contract on BSV
随机推荐
测试用例设计方法——因果图法
【第 04 章 基于Hough变化的答题卡识别】
ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)
[bit operation] leetcode1009 Complement of Base 10 Integer
联发科技 --联发科技简介++附上笔经面经
Curl requests at the server command line
稳扎稳打学爬虫08—Selenium的使用方法详解
The 8th "Internet +" competition - Bi ran, an outstanding architect of Baidu, interprets the proposition of industrial circuit
LeetCode+ 46 - 50
第 18 章 基于GUI搭建通用视频处理工具matlab应用GUI实现
Cache consistency of arm
第298场力扣周赛个人题解
Copy in pytorch_ Summary of differences between (), detach (), data (), and clone () operations
acwing 835. Trie string statistics
MBA-day18 消元法
【第 14 章 基于主成分分析的图像压缩和重建--matlab深度学习实战案例】
shadertoy 实现简易指南针
digital signal processing
DAST black box vulnerability scanner part 4: scanning performance
Preliminary competition of noip improvement group III. problem solving exercise set noip1995-noip2018