select a.* from A a 
where exists ( select 1 from B b where a.id=b.id )

 public List exist(){
  List result;
  Array A=(select * from A)   for(int i=0; i<A.length; i++) {
  if(exists(A[i].id) { //执行select 1 from B b where b.id=a.id是否有记录返回
  result.add(A[i]);
  }
  }
  return result;
}

2.in

select * from A
where id in ( select id from B )

 public List in(){
  List result;
  Array A = (select * from A);
  Array B = (select id from B);   for(int i=0; i<A.length; i++) {
  for(int j=0; j<B.length; j++) {
  if(A[i].id == B[j].id) {
  result.add(A[i]);
  break;
  }
  }
  }
  return result;
}

A表10000条记录,B表1000000条记录,那么最多有可能遍历10000*1000000次,效率很差.

A表10000条记录,B表100条记录,那么最多有可能遍历10000*100次,遍历次数大大减少

结论:

子查询表大的用exists,子查询表小的用in

3. in与 =

select name from student where name in ('zhang','wang','li','zhao');

select name from student where name='zhang' or name='li' or name='wang' or name='zhao';

exist & in的更多相关文章

  1. Android之Dedug--Circular dependencies cannot exist in AnimatorSet

    今日,在学习AnimatorSet时,使用play.with.after.before时,代码书写如下: ObjectAnimator animator1 = ObjectAnimator.ofFlo ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. MySQL: Table 'mysql.plugin' doesn't exist的解决

    安装解压版MySQL以后,不能启动,日志里面出现了这个错误: MySQL: Table 'mysql.plugin' doesn't exist 这是因为mysql服务启动时候找不到内置数据库&quo ...

  4. 解决 release-stripped.ap_' specified for property 'resourceFile' does not exist.

    设置buildTypes里的release的shrinkResources为false即可,如果是 release-stripped.ap_' specified for property 'reso ...

  5. Mac 下locate命令使用问题WARNING: The locate database (/var/db/locate.database) does not exist.

    想在Mac下使用locate时,提醒数据库没创建: WARNING: The locate database (/var/db/locate.database) does not exist. To ...

  6. CS0103: The name ‘Scripts’ does not exist in the current context解决方法

    转至:http://blchen.com/cs0103-the-name-scripts-does-not-exist-in-the-current-context-solution/ 更新:这个bu ...

  7. 执行mysqld_safe报错:mysqld does not exist or is not executable

    执行mysqld_safe报错: [root@edu data]# /usr/local/mysql5.7/bin/mysqld_safe --user=mysql160427 12:41:28 my ...

  8. tomcat报错java.lang.IllegalArgumentException: Document base XXXXX does not exist or is not a readable directory

    启动tomcat的时候报如下错误: java.lang.IllegalArgumentException: Document base F:\java\tools\tomcat\me-webapps\ ...

  9. mysqldump:Couldn't execute 'show create table `tablename`': Table tablename' doesn't exist (1146)

    遇到了一个错误mysqldump: Couldn't execute 'show create table `CONCURRENCY_ERRORS`': Table INVOICE_OLD.CONCU ...

  10. mysql [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist (转载)

    mysql报错Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist 2013-11-2 ...

随机推荐

  1. hystrix-turbine实现多服务监控

    原文地址:http://www.cnblogs.com/skyblog/p/5633757.html 1.   概述 Demo地址:http://git.oschina.net/zhou666/spr ...

  2. .Net基础——程序集与CIL HttpClient封装方法 .Net Core 编码规范 C#中invoke和beginInvoke的使用 WebServeice 动态代理类

    .Net基础——程序集与CIL   1. 程序集和CIL: 程序集是由.NET语言的编译器接受源代码文件产生的输出文件,通常分为 exe和dll两类,其中exe包含Main入口方法可以双击执行,dll ...

  3. http协议---简述

    http(Hypertext transfer protocol)超文本传输协议,通过浏览器和服务器进行数据交互,进行超文本(文本.图片.视频等)传输的规定. 也就是说,http协议规定了超文本传输所 ...

  4. Pycharm快捷键小结

    1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性)Ctrl + Alt + Space 快速导入任意类Ctrl + Shift + Enter 语句完成Ctrl + ...

  5. nginx源码学习_数据结构(ngx_int_t)

    nginx中关于整型的数据结构位于src/core/ngx_config.h中 结构比较简单,就是一个typedef的操作,具体如下: typedef intptr_t ngx_int_t; type ...

  6. java - day11 - OverRideTest

    概念 1.重写:看调用方法的对象:如果调用的是子类对象,则无论父类/子类引用类型,调用的都是重写后的方法,如果想调用父类的方法,用super.方法 来调:如果调用的是父类对象,则调用的是父类重写前的方 ...

  7. python C example:encode mp3 code

    #include <stdio.h> #include <stdlib.h> #include <lame.h> #define INBUFSIZE 4096 #d ...

  8. Unity3D游戏开发之游戏读/存档功能在Unity3D中的实现

    喜欢我的博客请记住我的名字:秦元培,我的博客地址是:http://qinyuanpei.com 转载请注明出处,本文作者:秦元培, 本文出处:http://blog.csdn.net/qinyuanp ...

  9. Blue Jeans - poj 3080(后缀数组)

    大致题意: 给出n个长度为60的DNA基因(A腺嘌呤 G鸟嘌呤 T胸腺嘧啶 C胞嘧啶)序列,求出他们的最长公共子序列 使用后缀数组解决 #include<stdio.h> #include ...

  10. IE6鼠标悬停Bug

    当鼠标放置于某个文字链接之上,文字或文字背景改变为其他颜色或样式的效果是我们最经常见到的鼠标悬停效果.在CSS中,这个效果靠伪元素:hover来实现,只不过在文字链接中:hover被应用在了锚点元素& ...