当前位置:网站首页>搞明白 left join、right join和join的区别
搞明白 left join、right join和join的区别
2022-06-09 08:05:00 【xcbzsy】
left join、join、right join和inner join等等各种join的区别。网上搜,最常见的就是一张图解图,如下:
一、left join
left是左边的意思,join是连接的意思,连起来就是“左连接”,表1左连接表2,以左为主,表示以表1为主,关联上表2的数据,查出来的结果显示左边的所有数据,然后右边显示的是和左边有交集部分的数据。如下:
select * from subject
left join score on subject.id = score.id

二、right join
right是右边的意思,join是连接的意思,加起来就是“右连接”,表1右连接表2,以右为主,表示以表2为主,关联查询表1的数据,查出表2所有数据以及表1和表2有交集的数据,如下:
select * from subject
right join score on subject.id = score.id

三、join
join,其实就是“inner join”,为了简写才写成join,两个是表示一个的,内连接,表示以两个表的交集为主,查出来是两个表有交集的部分,其余没有关联就不额外显示出来,这个用的情况也是挺多的,如下:
select * from subject
join score on subject.id = score.id

Join 等同于 inner join : 表示两个表都必须存在的
left join 表示以左边的表为基准,不管你右边的表有没有都显示
right join和left join刚好相反
full outer join表示只要在两个表中任何一个表中有的都显示
边栏推荐
- C语言复习12
- Simple practice of bouncing shell with NC and Bash
- homebrew安装mysql
- No, you still can't read the log with requestid?
- C language review 11
- Market Research - current situation and future development trend of global and Chinese dental zirconia materials market
- Market Research - current situation and future development trend of ethylene absorbent package market in the world and China
- Confusing output from infinite recursion within try catch
- SQL or NoSQL, you will understand after reading this article
- XML JSON yaml conversion
猜你喜欢

Selenium: element positioning

【读点论文】EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks网络结构要像身材一样匀称且体量和处理能力匹配

How do I add the hours of the current date in SQL Server- How to add hours to current date in SQL Server?

mysql根据父节点递归查询所有子节点,List转树形结构工具类

Compiling opencv4.5.5 with CUDA (4.2.0+cuda11.1+cudnn8.0.5 failed)

Robot_ Framework: Keywords

YOLOv5添加注意力机制的具体步骤

How do I create comma separated lists using SQL queries- How do I create a comma-separated list using a SQL query?

2022 Chinese cook (elementary) examination question bank and online simulation examination

Sql Or NoSql,看完这一篇你就懂了
随机推荐
C语言复习8
R language through rprofile Site file, custom configuration of R language development environment startup parameters, shutdown parameters, use file Edit function edit configuration file
puzzle(105)平面逆推
Market Research - current situation and future development trend of global and Chinese floating fish feed market
Clickhouse distributed table & local table & Clickhouse realize time series data management and mining
Taobao classification encyclopedia and its grouping (mysql, XLS) files, hierarchical relationship, spelling, hierarchy, hierarchical tree, tips, data on February 28, 2022
84.1%受访家长感到身边喜欢用电子产品哄孩子的家长多
Pushmall push and paste sharing e-commerce plan update completed in May 2022
MySQL: grouping query
实时监控,智能预警,疾控中心的战疫“速度”
Redis large key
Market Research - current market situation and future development trend of pirox ketolamine for personal care in the world and China
PHP get last Monday, get the last week date of the specified date, last Monday
Caffe installation steps
TCP connection establishment and termination, TCP state transition
Market Research - current situation and future development trend of global and Chinese cosmetic grade ascorbic acid glucoside Market
Summary of MySQL knowledge points
redis核心知識點總結(超詳細)
Specific steps for yolov5 to add attention mechanism
【读点论文】MobileDets: Searching for Object Detection Architectures for Mobile Accelerators,适配不同硬件平台的搜索方案