exist & in
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的更多相关文章
- Android之Dedug--Circular dependencies cannot exist in AnimatorSet
今日,在学习AnimatorSet时,使用play.with.after.before时,代码书写如下: ObjectAnimator animator1 = ObjectAnimator.ofFlo ...
- 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 ...
- MySQL: Table 'mysql.plugin' doesn't exist的解决
安装解压版MySQL以后,不能启动,日志里面出现了这个错误: MySQL: Table 'mysql.plugin' doesn't exist 这是因为mysql服务启动时候找不到内置数据库&quo ...
- 解决 release-stripped.ap_' specified for property 'resourceFile' does not exist.
设置buildTypes里的release的shrinkResources为false即可,如果是 release-stripped.ap_' specified for property 'reso ...
- 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 ...
- 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 ...
- 执行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 ...
- 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\ ...
- 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 ...
- 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 ...
随机推荐
- 工作总结 razor 接收datatable
- 执行”spark-shell –master yarn –deploy-mode client”,虚拟内存大小溢出,报错
在Hadoop 2.7.2集群下执行如下命令: spark-shell --master yarn --deploy-mode client 爆出下面的错误: org.apache.spark.Sp ...
- PIL之基础应用
>>> from PIL import Image >>> #读取图像文件 ... >>> gal=Image.open('/Users/simi ...
- undefined reference to `shm_unlink'
1.问题描述: 在编译一个程序的时候提示这样的错误: BLog.cpp:(.text+0x5fc): undefined reference to `shm_unlink'DBLog.cpp:(.te ...
- python c example2:pylame2
#include <Python.h> #include <lame.h> //pyton object variables typedef struct{ PyObject_ ...
- deepin linux下eclipse c/c++ 调试开源代码
1.deepin linux 下使用eclipse c/c++ 调试2. 编译选项,-g3 -O0,-g3表示输出调试信息,-O0不优化代码(第一个字母o的大写,第二个是数字0) 3.必备环境: gd ...
- SQL数据库查询练习题
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- mongodb更新器
Name Description $inc Increments the value of the field by the specified amount. $mul Multiplies the ...
- Vuex 2 入门与提高。
从计数器开始 让我们从一个简单的计数器,开始进入Vuex 的世界: 计数器应用的数据模型很简单:使用一个counter属性来表示计数器的 当前值就够了. 在Vue实例的created钩子 中,应用启动 ...
- Win10系统如何配置Tomcat环境变量
我们知道win10用户在配置Tomcat环境变量的时候,首先需要配置JAVA,这样才能配置Tomcat环境.很多用户并不知道要如何进行配置,下面就给大家介绍win10系统怎样Tomcat环境变量的. ...