select xxx from tableA, tableB where tableA.name = "a" and tableA.id = tableB.id and tableB.name="b"
- tableA 是驱动表,用于数据提供
- tableB 是被驱动表,用于数据关联
- 操作
- tableA.name 从 tableA 中索引过滤出一批数据
- tableB.name 从 tableB 中索引过滤出一批数据
- tableA.id = tableB.id 将上面两组数据进行数据关联
驱动表
left join 左表是驱动表right join 右表是驱动表join mysql 优化器会选择小表为驱动表
inner join, outer join
inner join 关联条件是 on or where
where 和 on 是等价的,即 mysql 优化器会将 on 优化为 where
left join 和 right join 关联条件就是 on
- 至于
where 和 on 的选择,需要根据实际业务 - 比如
left join 下,on 操作不管条件是否满足,都会返回左边数据,然后根据 where 进行查询