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. 用Emit技术替代反射

    之前在上篇博客说到用表达式来替代反射机制,可以获得较高的性能提升.这篇我们来说说用Emit技术来替代反射. System.Reflection.Emit命名空间类可用于动态发出Microsoft中间语 ...

  2. WPF入门教程系列四

    WPF之Binding的使用(二) 一.  前言 初学WPF经常被Binding搞得苦不堪言,Binding的重用性就不做介绍了,在WPF应用程序开发中Binding是一个非常重要的部分.WPF也是近 ...

  3. webpack 与 热编译webpack-dev-server

    webpack.config.js 只需要注意加大加粗的地方. var webpack = require("webpack"); var HtmlWebpackPlugin = ...

  4. 整理了一下浅墨大神的Visual C++/DirectX 9.0c的游戏开发手记

    还是非常棒的博客,只是没有一个文件夹.所以自己做了一个山寨文件夹在这里.便于随时查找. 前面31期从略. [Visual C++]游戏开发笔记三十二 浅墨DirectX提高班之中的一个 DirectX ...

  5. Atitit.跨语言反射api 兼容性提升与增强 java c#。Net  php  js

    Atitit.跨语言反射api 兼容性提升与增强 java c#.Net  php  js 1. 什么是反射1 1.1.       反射提供的主要功能:1 1.2.       实现反射的过程:1 ...

  6. 学习spring in action 第一天

    这段时间,开始学习java吧,因为C sharp 学习了java的大量语法格式,所以,留意下,就不会错了,java 有的c sharp也有,而且之前我也学习过java的桌面开发,但是一下子上来就要自己 ...

  7. [转]成员函数指针与高性能的C++委托

    原文(作者:Don Clugston):Member Function Pointers and the Fastest Possible C++ Delegates 译文(作者:周翔): 成员函数指 ...

  8. nginx 中location和root,你确定真的明白他们关系?

    最近公司开发新项目,web server使用nginx,趁周末小小的研究了一下,一不小心踩了个坑吧,一直404 not found!!!!!当时卡在location和root中,但是网上却比较少聊这方 ...

  9. linux下独立core2.1部署发布过程

    1.vs2017独立发布.linux-64 2.winscp上传到当前用户下面.ubuntu tsl64来讲 3.超级用户sudo su 4.zip解压缩 uzip xxx.zip -d ../../ ...

  10. mysql explain的解释

    详解MySQL中EXPLAIN解释命令 explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上e ...