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
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-21 11:19:44