ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**左外连接(左连接):** JOIN 操作符左边表中符合 ON 子句的所有记录将会被返回。 ```sql select * from left_tbl; +--------------+----------------+---------------+--+ | left_tbl.id | left_tbl.name | left_tbl.age | +--------------+----------------+---------------+--+ | 1 | 张三 | 20 | | 2 | 李四 | 22 | | 3 | 王五 | 25 | +--------------+----------------+---------------+--+ select * from right_tbl; +---------------+-----------------+----------------+--+ | right_tbl.id | right_tbl.name | right_tbl.age | +---------------+-----------------+----------------+--+ | 1 | 张三 | 20 | | 2 | 李四 | 22 | | 4 | 王五 | 25 | +---------------+-----------------+----------------+--+ ############ 左连接 ############## -- 左表全部查询,右表没有的用NULL填充 -- left join 是 left outer join 的简写 select * from left_tbl lt left join right_tbl on lt.id=rt.id; +--------+----------+---------+--------+----------+---------+--+ | lt.id | lt.name | lt.age | rt.id | rt.name | rt.age | +--------+----------+---------+--------+----------+---------+--+ | 1 | 张三 | 20 | 1 | 张三 | 20 | | 2 | 李四 | 22 | 2 | 李四 | 22 | | 3 | 王五 | 25 | NULL | NULL | NULL | +--------+----------+---------+--------+----------+---------+--+ ```