mysql数据查询之多表链接
-全连接(无条件)-
select * from course,sc;
//每个表的每行都与其他表每行交叉,包含所有表中出现的列。
-内连接(条件)-
select * from course join sc
on course.cno=sc.cno where sc.cno='c02';
-外连接-
左外连接
select teaching.tno,tname from teaching left outer join teacher
on teaching.tno=teacher.tno and teacher.tno='102';
//查询所有老师的老师号且显示老师号为“102”的老师姓名。
右外连接
select student1.sno,sname,cno from student1 right outer join sc
on student1.sno=sc.sno and cno='c02';
//查询所有课程号及选修了"c02"课程的同学学号和姓名。
-子查询-
in子查询
select tname from teacher
where tno in(select tno from teaching where cterm=2);
//查询第二个学期开课的老师名字。
比较子查询(all,some,any)
select * from sc
where degree>all
(select degree from sc where cno='c03');
//查询所有比选修了“c03”的分数高的成绩基本信息
(因为表中cno=“c02”时有一个空值,所以不能作比较)
吾矣
终极愿望世界和平୧⍤⃝🇨🇳