在数据库中tableA连接tableB如下:
tableA:
a1 a2
1 1
2 2
3 2
4 3
tableB:
b1 b2
2 1
2 2
3 3
3 4
6 5
笛卡尔积:
select * from tableA, tableB.
1 1 2 1
1 1 2 2
1 1 3 3
1 1 3 4
1 1 6 5
2 2 2 1
2 2 2 2
2 2 3 3
2 2 3 4
2 2 6 5
3 2 2 1
3 2 2 2
3 2 3 3
3 2 3 4
3 2 6 5
4 3 2 1
4 3 2 2
4 3 3 3
4 3 3 4
4 3 6 5
内连接:
select * from tableA a inner join tableB b where a.a2 = b.b1.
2 2 1
2 2 2
3 2 1
3 2 2
4 3 3
4 3 4
左外连接:
select * from tableA a left join tableB b where a.a2 = b.b1.
1 1 null
2 2 1
2 2 2
3 2 1
3 2 2
4 3 3
4 3 4
右外连接:
select * from tableA a right join tableB b where a.a2 = b.b1.
2 2 1
2 2 2
3 2 1
3 2 2
4 3 3
4 3 4
null 6 5
全连接:
select * from tableA a full join tableB b where a.a2 = b.b1.
1 1 null
2 2 1
2 2 2
3 2 1
3 2 2
4 3 3
4 3 4
null 6 5