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;