数据库查询问题sql语言

来源:百度知道 编辑:UC知道 时间:2024/05/14 01:35:34
有三个表,主要相关属性如下:student表:sno(学号)、sname(姓名);
course表:cno(课程号);sc表:sno、cno
现有如下语句,是要执行什么?
(1)select sname from student where not exists(select * from course where not exists(select * from sc where sno=student.sno and cno=course.cno))
(2)select distinct sno from sc scx where not exists(select * from sc scy where scy.sno='95002' and not exists (select * from sc scz where scz.sno=scx.sno and scz.cno=scy.cno))
第一个好像是查选了全部课的学生姓名,第二个是查询至少选修了学生95002选修的全部课程的学生号码,可是是为什么呢?请高手指教一下,小弟初学,不是很懂,讲说得详细一些,谢谢了!!!
谢谢您的帮助
第二个是在同一个表中反复连接,所以设了3个名。scx、scy、scz~~这样说能知道是什么意思了吗?只知道老师讲的时候是这个意思,可是为什么这样可以执行实在是想不起来了~~
sc scx 太具体的忘了,就是这个连接要连接到自身表中,所以要把表设成scx、scy、scz,sc scx就是设了其中一个~~

因为你第一个:select * from course where not exists(select * from sc where sno=student.sno and cno=course.cno)查询出来的是cno在student
表中根本没有就是不存在了!所以所有的姓名都被检索啊!
第二个看不懂.

sc scx 这个是什么呀