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 ...
随机推荐
- cordova开发自己定义插件
以下是自己定义cordova插件的基本入门.做插件的小白可以參考一下哈,兴许会更新插件的进阶博客,希望大家可以共同学习共同进步 1.环境搭建 cordova插件开发前须要安装一些软件和配置环境 1.1 ...
- 论C++STL源代码中关于堆算法的那些事
关于堆,我们肯定熟知的就是它排序的时间复杂度在几个排序算法里面算是比較靠上的O(nlogn)常常会拿来和高速排序和归并排序讨论,并且它还有个长处是它的空间复杂度为O(1), 可是STL中没有给我们提供 ...
- Sql常用语法总结
SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRAN ...
- Python内置函数之all()
all()函数返回值不是True就是False. 它只能传入一个参数,而且参数必须是可迭代对象,换句话说,参数不是元组就是列表(通常情况下). all()中的可迭代对象所有元素值为True或者不包含元 ...
- input子系统分析(转)
转自:http://www.linuxidc.com/Linux/2011-09/43187.htm 作者:作者:YAOZHENGUO2006 Input子系统处理输入事务,任何输入设备的驱动程序都可 ...
- hdu5800 To My Girlfriend dp 需要比较扎实的dp基础。
To My Girlfriend Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- ACM Computer Factory - poj 3436 (最大流)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5949 Accepted: 2053 Special Judge ...
- boot2docker里报"no space left on device" error的解决方法
docker中pull远程image时:报 no space left on device virtualbox中调大虚拟内存即可.. 之前调的硬盘大小...
- http://localhost:8080请求用户名和密码。信息为:“XDB” 解决办法
windows查看端口占用情况 cmd下 netstat -ano 查看端口和对应的服务 为2520 Oracle的服务 源博客: http://blog.163.com/jxguo_05/blog/ ...
- Android Studio3.0 配置ButterKnife出错的解决
需要注意的问题: (1)ButterKnife.bind(this);必须在设置布局之后进行初始化: 官方升级到了8.8.1了 compile 'com.jakewharton:butterknife ...