1、左外连接将左表中要丢弃的记录保留在结果集中,右表中对应的部分用null填充。
mysql> select a.*,b.* from course as a left join rollcall as b on a.course_id=b.course_id; +-----------+-------------+------+---------+-----------+-----------+------+-----------+------------+--------------+--------------+---------+ | course_id | course_name | time | teacher | classroom | t_command | db | course_id | student_id | student_name | teacher_name | command | +-----------+-------------+------+---------+-----------+-----------+------+-----------+------------+--------------+--------------+---------+ | 1 | 1234 | 123 | 123 | 123 | 123 | 2 | 1 | 1501010096 | 于宗云 | 123 | 123 | | 2 | 123 | 123 | 123 | 123 | 123 | NULL | NULL | NULL | NULL | NULL | NULL | +-----------+-------------+------+---------+-----------+-----------+------+-----------+------------+--------------+--------------+---------+
2、右外连接,将右表中要丢弃的记录保留在结果集中,左表中对应的部分用null填充。
mysql> select a.*,b.* from course as a right join rollcall as b on a.course_id=b.course_id; +-----------+-------------+------+---------+-----------+-----------+----+-----------+------------+--------------+--------------+---------+ | course_id | course_name | time | teacher | classroom | t_command | db | course_id | student_id | student_name | teacher_name | command | +-----------+-------------+------+---------+-----------+-----------+----+-----------+------------+--------------+--------------+---------+ | 1 | 1234 | 123 | 123 | 123 | 123 | 2 | 1 | 1501010096 | 于宗云 | 123 | 123 | +-----------+-------------+------+---------+-----------+-----------+----+-----------+------------+--------------+--------------+---------+ 1 row in set (0.00 sec)
3、全外连接:将左表和右表中要丢弃的记录保留在结果集中。
右表和左表中相应的部分用null填充。
# 由于本机没有安装oracle所以没有验证第一句sql的正确性 Select * from table1 full join table2 on table1.C=table2.C
以上就是mysql外连接的类型介绍,希望对大家有所帮助。更多mysql学习指路:
推荐操作系统:windows7系统、mysql5.8、DELL G3电脑