高级查询

一.子查询:

 1简单子查询语法:

    select  * from 表名 where 列 运算符 (子查询)

   例:

     select  name from student where id =(select id from result where score=60)--查询分数等于60的一个学生

 2.in子查询:

    in子查询可以反回多个记录

      语法:

    select * from 表名 where 列 in (子查询)

      例:

    select  name from student where id in(select id from result where score>60)--查询分数大于60的所有学生

   3.not in子查询

     not in子查询可以查询到没有达成条件的结果

    语法:

       select * from 表名 where 列 not in (子查询)

       例:

        select  name from student where id not in(select id from result where score>60)--查询分数没有大于60的所有学生

    4.exists子查询:


         exists关键字可以检测数据是否存在.一般用于if语句的存在检测.

         语法:

           if exists(子查询)

          例:

          if exists(select * from result where subjectno=(select subjectno from subject where subjectname='Java'))  

     5.not exists子查询:

      exists和in一样,添加not关键字可以实现取反操作,not exists表示不存在.

          例:

          if not exists(select * from result where subjectno=(select subjectno from subject where subjectname='Java'))  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值