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


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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM