连接查询
三种连接方式
内连接查询
关键词:inner join … on 案例: 1.查询 对应班级的学生以及班级信息
代码语言:javascript复制select * from students inner join classes on students.cls_id=classes.id;
2.查询 对应班级的学生以及班级信息,按照班级进行排序
代码语言:javascript复制select c.name, s.* from students as s inner join classes as c on s.cls_id=c.id order by c.name
左连接查询
关键词:left join … on 案例: 1.查询 每位学生以及班级信息
代码语言:javascript复制select * from students left join classes on students.cls_id=classes.id;
右连接查询
关键词:right join … on 案例: 1.查询 每个班级对应的学生信息
代码语言:javascript复制select * from students right join classes on students.cls_id=classes.id;
子查询
类似嵌套 案例: 1.查询 最高的学生信息
代码语言:javascript复制select * from students where height = (select max(height) from students);