数据库内连接、外连接图解

1. 内连接(INNER JOIN)

内连接分隐式和显式。

(1)隐式的内连接,没有INNER JOIN,形成的中间表为两张表的笛卡儿积。

SELECT student.name,score.codeFROM student,score WHERE score.code=student.code;

(2)显式的内连接,有INNER JOIN,形成的中间表为两个表经过ON条件过滤后的笛卡尔积。

SELECT student.name,score.codeFROM student INNER JOIN score ON score.code=student.code;

2. 外连接(OUTER JOIN)

(1)左外连接(left outer join)

返回指定左表的全部行+右表对应的行,如果左表中数据在右表中没有与其相匹配的行,则在查询结果集中显示为空值。

SELECT student.name,score.codeFROM student LEFT JOIN score ON score.code=student.code;

(2)右外连接(right outer join)

与左外连接类似,是左外连接的反向连接。

SELECT student.name,score.codeFROM student RIGHT JOIN score ON score.code=student.code;

原文地址:https://www.cnblogs.com/yukifun/p/13397040.html