exists(查询语句) : 存在的意思,判断一张表里面的记录是否存在与另外一张表中。
emp表中的部门号为 10,20,30
oracle exists
部门表中,dept中的部门号为 9,10,20,30,40,50
oracle exists

需求,查询出有员工的部门(查询出存在于emp表中的dept信息)
oracle exists
似乎没有效果,结果查询出的是所有的dept信息。
指定deptno的值,也没效果
select * from dept d1 where exists(select * from emp e1 where e1.deptno=10 );等同于
select * from dept d1 where 1 = 1

oracle exists


改进下写法,添加exists 后面,emp表与dept表的关联关系
oracle exists

总结:在使用exists的时候,要注意关联exists前后两张表。 

相关文章:

  • 2022-01-21
  • 2022-01-31
  • 2022-01-29
  • 2021-11-20
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2022-01-10
  • 2021-12-21
  • 2021-12-03
  • 2022-02-14
  • 2022-01-21
  • 2021-11-10
相关资源
相似解决方案