SQL连接能够分为内连接、外连接、交叉连接。
1.内连接:内连接查询操作列出与连接条件匹配的数据行,它使用比較运算符比較被连接列的列值。
1.1 select * from Table1 as a, Table2 as b where a.id= b.id
1.2 select * from Table1 as a inner join Table2 as b on a.id = b.id
外连接
2.1 左外连接(简单说,左表数据全显示。右不匹配的显示null)select * from Table1 as a left join Table2 as b on a.id = b.id
2.2 右外连接(同上相反)select * from Table1 as a right join Table2 as b on a.id = b.id
2.3 全连接(当某行在还有一个表中没有匹配行时,则还有一个表的选择列表列包括空值。假设表之间有匹配行。则整个结果集行包括基表的数据值)
select * from Table1 as a full outer join Table2 as b on a.id = b.id
3.左表中的每一行与右表中的全部行组合。交叉联接也称作笛卡尔积
select * from Table1 as a cross join Table2 as b order b a.id