in or exits

2024-01-27 07:38
文章标签 exits

本文主要是介绍in or exits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 in 和 exits存在的原因

   不是所有的查询都有关联

2 in 和 exits并存的原因

   in 和 exits 有各自的优势

3 in 和 exits的原理

   in  先执行子查询 然后执行主表查询,exits先执行主表查询,后执行子查询过滤

4 何时使用in

   过滤性不强,主表不是大表

   例:

 

select * from dep d where d.parent_id in (  select s.dep_id from student  s where s.stu_name like '%小明%'
)
 

5 何时使用exits

   过滤性很强,主表可以是大表(主要靠过滤)
  例:

select * from dep d where d .id = 101 and exits (select 1 from student s where s.stu_name like '%小明%')
 

6 in 和 exits 对比

   适合用in的 查询相关分类

       select * from category c where c.parent_id in(select i.category_id from info i where info.name like '%中国%' ) 

       要比exits有优势

   适合用exits的某时间段的相关分类

     select * from category  createDate< to_date('2012-09-29 10:00:00','yyyy-mm-dd hh24:mi:ss')

and createDate< to_date('2012-10-01 00:00:00','yyyy-mm-dd hh24:mi:ss')

and exits (select i.category_id from info i where info.name like '%中国%' )  

      要比in有优势

7 总结in与exits

   如果主表是大表 不首先考虑exits,但是如果过滤性很强要考虑exits.

   如果主表是小表,两种差不了多远。因为有时候exits的优势是在过滤上 如果主表本来数据很少过滤的影响不大。

 

 

这篇关于in or exits的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/649520

相关文章

deepseed 单机多卡程序报错:exits with return code -7

现象:exits with return code -7原因:Setting the shm-size to a large number instead of default 64MB when creating docker container solves the problem in my case. It appears that multi-gpu training relies on

Mysql的in与exits

Mysql的in与exits IN和EXISTS是MySQL中用于子查询的两种不同的条件操作符。它们在使用和实现上有一些区别。 IN 操作符: IN操作符用于判断一个值是否在一个集合内。它可以用于子查询中,检查主查询的某一列是否在子查询返回的结果集中。 SELECT column_nameFROM your_tableWHERE column_name IN (SELECT anoth

Oracle select in/exists/not in/not exits

in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询。 一直以来认为exists比in效率高的说法是不准确的。 如果查询的两个表大小相当,那么用in和exists差别不大。 in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询。 一直以来认为exists比in效率高的说法是不准确的。 如