join 和left join
时间: 2023-10-11 14:13:36 浏览: 83
join和left join是SQL中用于连接多个表的操作。
join(内连接)是以两个表的交集为主,查出来的结果只显示两个表有交集的部分,其他没有关联的数据不显示出来。语法示例如下:
```
SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
```
left join(左连接)是以左表为主,关联上右表的数据,并将左表的所有数据都显示出来,右表中和左表有交集的数据也会显示在结果中。语法示例如下:
```
SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;
```
简而言之,join是内连接,只显示有交集的数据;left join是左连接,显示左表的所有数据,以及和左表有交集的右表数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [一分钟让你搞明白 left join、right join和join的区别](https://blog.csdn.net/Li_Jian_Hui_/article/details/105801454)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文