内连接
inner join on / inner outer join on
隐式内连接:select * from table1,table2 where table1.id= table2.id;
标准内连接:select * from table1 inner join table2 on table1.id= table2.id;
自然连接:select * from table1 natural join table2;(笛卡尔积=所有可能的组合)
外连接
1.左连接(左外连接)
left join on / left outer join on
显示左表(table1)中的所有记录,显示右表(table2)中符合搜索条件的记录,右表记录不足的地方都为null;
- select * from table1 left join table2 on table1.id= table2.id;
2.右连接(右外连接)
right join on / right outer join on
显示右表(table2)中的所有记录,显示左表(table1)中符合搜索条件的记录,左表记录不足的地方都为null;
- select * from table1 right join table2 on table1.id= table2.id;
3.全连接(全外连接)(完全连接)
full join on / full outer join on
交叉连接
cross join (不带on字句)(笛卡尔积)
返回左表中的所有行,左表中的每一行与右表中的所有行组合。交叉连接接也称作笛卡尔积。
隐式的交叉连接,没有cross join
显式的交叉连接,使用cross join
联合连接(union join)
找出全外连接和内连接之间差异的所有行。这在数据分析中排错中比较常用。