、内连接、左连接、右连接
学生表:
班级表:
1、内连接:inner join
select * from stu1 inner join class on stu1.grade=class.grade;
select s.*,c.id as c_id,c.grade as c_grade,room from stu1 as s inner join class as c on s.grade=c.grade;
2、左右连接
左链接:左表为主表,取出主表中所有记录,然后去匹配另一个表进行连接,匹配成功,保留数据;匹配不成功的话,另一个表的字段置为NULL.
右连接:道理同左链接
左表 + left ight + join + 右表 + on + 左表.字段 = 右表.字段;
select s.*,c.room from stu1 as s left join class as c on s.grade=c.grade;
delect s.*,c.room from stu1 as s right join class as c on s.grade=c.grade;