LEFT JOIN与INNER JOIN区别(Difference between left join and inner join)

说明

与 的区别就是 只显示出符合条件的结果,而 会显示出主表中所有的内容,即使在添加连接表中找不到符合条件的结果。

left join
inner join
inner join
left join

示例


# right join
# sql语句如下:
select * from A
right join B 
on A.aID = B.bID

# 结果如下:
aID     aNum     bID     bName
1     a20050111    1     2006032401
2     a20050112    2     2006032402
3     a20050113    3     2006032403
4     a20050114    4     2006032404
NULL     NULL     8     2006032408

# inner join
# sql语句如下: 
select * from A
innerjoin B 
on A.aID = B.bID

# 结果如下:
aID     aNum     bID     bName
1     a20050111    1     2006032401
2     a20050112    2     2006032402
3     a20050113    3     2006032403
4     a20050114    4     2006032404

————————

explain

The difference between and is that only qualified results will be displayed, and all contents in the main table will be displayed, even if no qualified results can be found in the added connection table.

left join
inner join
inner join
left join

Examples


# right join
# sql语句如下:
select * from A
right join B 
on A.aID = B.bID

# 结果如下:
aID     aNum     bID     bName
1     a20050111    1     2006032401
2     a20050112    2     2006032402
3     a20050113    3     2006032403
4     a20050114    4     2006032404
NULL     NULL     8     2006032408

# inner join
# sql语句如下: 
select * from A
innerjoin B 
on A.aID = B.bID

# 结果如下:
aID     aNum     bID     bName
1     a20050111    1     2006032401
2     a20050112    2     2006032402
3     a20050113    3     2006032403
4     a20050114    4     2006032404