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 ...
随机推荐
- oracle加入not null约束
在创建表时.为列加入not null约束,形式例如以下: column_name data_type [constraint constraint_name] not null 当中,constrai ...
- UVA 11014 - Make a Crystal(容斥原理)
UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, ...
- 283. Move Zeroes【easy】
283. Move Zeroes[easy] Given an array nums, write a function to move all 0's to the end of it while ...
- ipk CONTROL 目录的作用
CONTROL文件夹下的文件意义preinst - shell script,在ipk包开始安装前执行;postinst - shell script,在ipk包安装后执行; ...
- lamp环境编译安装curl扩展
Linux编译安装php扩展包curl 1.curl,主要用于发送http请求,是php的一个扩展包. 2.安装过程: (1)curl下载:http://curl.haxx.se/download.h ...
- hdu1695 GCD2 容斥原理 求x属于[1,b]与y属于[1,d],gcd(x,y)=k的对数。(5,7)与(7,5)看作同一对。
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...
- 12:Web及MySQL服务异常监测案例
[root@db01 scripts]# cat db_check.sh #!/bin/bash db_num=$(mysql -h172. -P3306 -uroot -poldboy123 -e ...
- Tomcat运行流程
Connector介绍 1.1 Connector的种类 Tomcat源码中与connector相关的类位于org.apache.coyote包中,Connector分为以下几类: Http Conn ...
- 图像增强之DDE---基于红外图像的数字图像细节增强DDE
(1)DDE应用背景 (2)DDE算法简介 (3)DDE 实现 (4)DDE 总结和不足 ----------author:pkf -----------------time:2-9 -------- ...
- Codeforces Round #398 (Div. 2) BCD
B:The Queue 题目大意:你要去办签证,那里上班时间是[s,t), 你知道那一天有n个人会来办签证,他们分别是在时间点ai来的.每个人办业务要花相同的时间x,问你什么时候来 排队等待的时间最少 ...