tb1
1 |
1111 |
2 |
1111 |
3 |
1111 |
tb2
1 |
[Null] |
2 |
[Null] |
3 |
66 |
4 |
55 |
1、
select t1.ID, t1.NAME,t2.id,t2.name
from TB1 t1 right join tb2 t2
on t1.id=t2.id
where t1.id is not null
结果
1 |
11 |
1 |
[Null] |
2 |
22 |
2 |
[Null] |
3 |
[Null] |
3 |
66 |
2、
select t1.ID, t1.NAME,t2.id,t2.name
from TB1 t1 right join tb2 t2
on t1.id=t2.id
and t1.id is not null
结果
1 |
11 |
1 |
[Null] |
2 |
22 |
2 |
[Null] |
3 |
[Null] |
3 |
66 |
[Null] |
[Null] |
4 |
55 |
两条语句结果是不一样的,第一条语句是对连接后的结果进行过滤,第二条语句是在连接前线对t1.id进行过滤,然后进行连接