1.left join(左连接)
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
left join 影响的左边的表,例如A表数据为:
A_ID | A_number |
1 | A20190701 |
2 | A20190702 |
3 | A20190703 |
4 | A20190704 |
5 | A20190705 |
B表数据为:
B_ID | B_number |
1 | B20190701 |
2 | B20190702 |
3 | B20190703 |
4 | B20190704 |
7 | B20190707 |
那么A left join B后数据表变为:
A_ID | A_number | B_ID | B_number |
1 | A20190701 | 1 | B20190701 |
2 | A20190702 | 2 | B20190702 |
3 | A20190703 | 3 | B20190703 |
4 | A20190704 | 4 | B20190704 |
5 | A20190705 | null | null |
2.right join(右连接)
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
AB表数据如上,右连接后,数据表变为:
A_ID | A_number | B_ID | B_number |
1 | A20190701 | 1 | B20190701 |
2 | A20190702 | 2 | B20190702 |
3 | A20190703 | 3 | B20190703 |
4 | A20190704 | 4 | B20190704 |
null | null | 7 | B20190707 |
3.inner join(等值连接)
inner join(等值连接) 只返回两个表中联结字段相等的行
AB表数据如上,等值连接后,数据表变为:
A_ID | A_number | B_ID | B_number |
1 | A20190701 | 1 | B20190701 |
2 | A20190702 | 2 | B20190702 |
3 | A20190703 | 3 | B20190703 |
4 | A20190704 | 4 | B20190704 |