mysql链接查询
Posted 我的牛肉面啊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql链接查询相关的知识,希望对你有一定的参考价值。
--链接查询
--内连接
--inner join...on
--查询有能够对应班级的学生以及班级信息
select * from student inner join classes on student.cls_id=classes,id;
--按照要求显示姓名,班级
select student.*,classes.name from student inner join classes on student.cls_id=classes,id;
--给数据表起名字
select s.*,c.name from student as s inner join classes as c on s.cls_id=c.id;
--在以上查询中,将班级姓名显示在第一列
select c.name,s.* from student as s inner join classes as c on s.cls_id=c.id;
--查询有能够对应班级学生以及班级信息,按照班级进行排序
select c.name,s.* from student as s inner join classes as c on s.cls_id=c.id order by c.name;
--当同一个班级的时候,按照序号排序
select c.name,s.* from student as s inner join classes as c on s.cls_id=c.id order by c.name,s.id;
--左链接
--left join...on
--查询每个学生对应的班级信息
--select * from student as s left join classes as c on s.cls_id=c.id;
--查询没有对应班级信息的学生
----select * from student as s left join classes as c on s.cls_id=c.id having c,id is null;
以上是关于mysql链接查询的主要内容,如果未能解决你的问题,请参考以下文章
MySQL多表查询 -- 2019-08-08 20:38:59