企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**内连接:** 只有进行连接的两个表中都存在与连接条件相匹配的数据才会被保留下来。 ```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 | +---------------+-----------------+----------------+--+ ############ 内连接 ############## 【写法1】:使用 join/on,join/on是inner join/on 简写 select * from left_tbl lt join right_tbl rt 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 | +--------+----------+---------+--------+----------+---------+--+ 【写法2】:使用where来代替join/on +--------+----------+---------+--------+----------+---------+--+ | lt.id | lt.name | lt.age | rt.id | rt.name | rt.age | +--------+----------+---------+--------+----------+---------+--+ | 1 | 张三 | 20 | 1 | 张三 | 20 | | 2 | 李四 | 22 | 2 | 李四 | 22 | +--------+----------+---------+--------+----------+---------+--+ ```