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. 单例模式获取JDBC连接

    package com.jdbc.test; import java.io.IOException; import java.io.InputStream; import java.sql.Conne ...

  2. JanusGraph的schema及数据建模

    每个JanusGraph都有一个schema,该schema由edge labels, property keys和vertex labels组成.JanusGraph的schema可以显式或隐式创建 ...

  3. 微信支付和微信支付通知基于sdk的说明

    前提是,有微信服务号(必须开通了支付功能,也就是说有了商户后台) (注意商户后台 安全目录 的设置,不然即使你写的没错误,也调用不成功) 公众号h5页面写法:  (购物车提交--我们上一步已经生成了订 ...

  4. dubbo_实现Hessian的远程调用协议

    1.优点 连接个数:多连接 连接方式:短连接 传输协议:HTTP 传输方式:同步传输 序列化:Hessian二进制序列化 适用范围:传入传出参数数据包较大,提供者比消费者个数多,提供者压力较大,可传文 ...

  5. Apache优化提高并发数量

    问题: 我们用lvs做了负载均衡.使用了两台server做login的服务.以及二次资源下载服务.可是在推广过程中.陆续有人反映server登录困难. 解决过程: 1.首先我们查看流量日志以及serv ...

  6. JAVA 利用SimpleDateFormat将String转换为格式化的日期

    1. /** * 使用用户格式提取字符串日期 * * @param strDate 日期字符串 * @param pattern 日期格式 * @return */ public static Dat ...

  7. 60. Search Insert Position 【easy】

    60. Search Insert Position [easy] Given a sorted array and a target value, return the index if the t ...

  8. 验证用户名,密码,验证码,发送alax请求进行登录代码

    //html代码 <div class="layui-form" id="larry_form"> <div class="layu ...

  9. ServletContext与Web应用以及Spring容器启动

    一.ServletContext对象获取Demo Servlet容器在启动时会加载Web应用,并为每个Web应用创建唯一的ServletContext对象. 可以把ServletContext看作一个 ...

  10. X264参考手册

    艺搜简介 基本语法: x264 [options]-o outfile infile 注意与ffmpeg的输入输出文件位置恰好相反: ffmpeg[options][[infile options]- ...