# 内连接语法select*from tb1 innerjoin tb2 ON 匹配条件 [where 条件];# where设置过滤条件:先⽣成笛卡尔积再从笛卡尔积中过滤数据(效率很低)select*from students INNERJOIN classes where students.cid=classes.id;# ON设置连接查询条件:先判断连接条件是否成⽴,如果成⽴两张表的数据进⾏组合⽣成⼀条结果记录select*from students INNERJOIN classes ON students.cid=classes.id;# 查询班里里男生的个人信息select*from students innerjoin classes on students.cid=classes.id where students.gender='男';
左连接 left join
# 左连接语法select*from left_tb1 LEFTJOIN right_tb1 ON 匹配条件 [where 条件];# 左连接显示左表全部数据,如果右表中不存在的数据则显示nullselect*from students LEFTJOIN classes ON students.cid =classes.id;
右连接 right join
select*from right_tb1 rightJOIN left_tb1 ON 匹配条件 [where 条件];# 右连接显示右表全部数据,如果左表中不存在的数据则显示nullselect*from students rightjoin classes on students.cid=classes.id;