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 ...
随机推荐
- ajax+webapi上传图片问题
自己想写一个原生的JS的图片上传,不想一直只是使用上传文件的框架 网上有很多jquery上传图片上传文件的插件,但是要不是用特定的后台框架接收,要不就是只能上传图片,不是文件,还有一些其他的问题,所以 ...
- 英语每日一句: What’s your point? 你究竟想说什么?
今天我们要学习的一句话是:What's your point? 你究竟想说什么?这句话在日常交流中非经常见,当对方说了非常多东西你仍不明确他究竟是什么意思时.你就能够问What's your poin ...
- 如何高效利用github提升自己
作为开源代码库以及版本控制系统,Github拥有超过900万开发者用户,是开发者打开程序开源大门的一扇窗口,也是开发者快速提升自己的一个重要途径.本文将从两个方面介绍github的使用方式. 和逛微博 ...
- Eclipse 浏览(Navigate)菜单
浏览 Eclipse 工作空间 浏览(Navigate)菜单提供了多个菜单可以让你快速定位到指定资源. 上图中 Open Type, Open Type in Hierarchy 和 Open Res ...
- PRINTDLG 打印对话框操作
typedef struct tagPD { DWORD lStructSize; HWND hwndOwner; HGLOBAL hDevMode; HGLOBAL hDevNames; HDC h ...
- 圆角头像----CSS3特效
w3c:http://www.w3school.com.cn/cssref/pr_border-radius.asp 定义和用法 border-radius 属性是一个简写属性,用于设置四个 bord ...
- ios -过滤字符串特殊字符
//过滤 " [ ] " + (NSString *)onTwoCommseparatedWithString:(NSString *)string { //过滤 " [ ...
- MySQL的下载及安装
前言:不仅要知其然,还要知所以然 MySQL数据库作为关系型数据库中的佼佼者,因其体积小,速度快,成本低,不仅受到了市场的极大追捧,也受到了广大程序员的青睐.接下来,就给大家说一下,MySQL的下载和 ...
- 第11章 Docker Registry 相关问题
11.1 我 docker push 的时候怎么报 authentication required 错误? 因为你没有登录.如果是向 Docker Hub 推送镜像,需要在注册一个用户: https: ...
- Jmeter BeanShell 引用变量报错jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Parse error at line 14, column 181 : Error or number too big for integer
如果你通过CSV Data Set Config或者_StringFromFile函数来参数化你的请求,需要特别注意当参数为纯数字时,jmeter会默认将其识别成int型数据,说明jmeter并不是默 ...