码迷,mamicode.com
首页 > 数据库 > 详细

mysql链接查询

时间:2020-02-23 20:17:19      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:查询   显示   mys   _id   内连接   起名字   sele   链接   left join   

--链接查询
--内连接
--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链接查询

标签:查询   显示   mys   _id   内连接   起名字   sele   链接   left join   

原文地址:https://www.cnblogs.com/zhongxiaoyan/p/12353269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!