Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN

数据库多表关联查询

student表

Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN_第1张图片

class表

Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN_第2张图片

1. JOIN等同于INNER JOIN,即内连接,不满足ON条件的会直接过滤掉,不显示

SELECT * FROM student s JOIN class c ON s.class_id = c.id

Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN_第3张图片

2. LEFT JOIN等同于LEFT OUTER JOIN,左外连接,不满足ON条件的会保留左边那张表的数据,右边表数据直接显示NULL

SELECT * FROM student s LEFT JOIN class c ON s.class_id = c.id

Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN_第4张图片

3. RIGHT JOIN等同于RIGHT OUTER JOIN,右外连接,不满足ON条件的会保留右边那张表的数据,左边表数据直接显示NULL

SELECT * FROM student s RIGHT JOIN class c ON s.class_id = c.id

Mysql 关键字JOIN,LEFT JOIN,RIGHT JOIN_第5张图片

你可能感兴趣的:(Mysql)