sunshinekevin

对exists及not exists的使用根据下面的示例进行解释

如sql:

select sname from student where exists (select * from score));

这里,如果select * from score语句查询到结果【只要不是Empty,就是查询到了结果】,则当执行exists判断的时候就会返回true,如果结果集为空,则exists判断结果为false。同理,not exists与exists判断结果相反。

 

exists一般用于内联查询如下:

表结构如图,查找任课教师中,没被匡明选过课的教师编号和姓名[编写sql查询]

 

select a.tno 教师编号,a.tname 教师姓名 from teacher a 
where exists(select *
                 from student b,score c ,course d 
                        where b.sno = c.sno and d.cno = c.cno and b.
                        sname=\'匡明\' and d.tno = a.tno
                    );

 

分类:

技术点:

相关文章:

  • 2021-08-29
  • 2021-08-18
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-09-14
猜你喜欢
  • 2021-08-03
  • 2021-08-03
  • 2021-08-03
  • 2021-09-14
  • 2021-11-10
  • 2021-07-21
相关资源
相似解决方案