文章目录
- [inner join](#inner join)
- [left join 和right join](#left join 和right join)
inner join
内连接是inner join ,只返回两个表匹配的数据行。
sql
select a.*,b.* from a inner join b on a.id = b.aid;
--等价于
select a.*,b.* from a join b on a.id = b.aid;
left join 和right join
左外连接和右外连接
主表数据全部返回,连接表有匹配则返回,无匹配返回空值
sql
select a.*,b.* from a left join b on a.id = b.aid;
select a.*,b.* from a right join b on a.id = b.aid;
b on a.id = b.aid;