not exists 与 select null,select 1的作用
来源:互联网 发布:影楼网络销售赚钱吗 编辑:程序博客网 时间:2024/06/04 01:01
1. 构建虚拟表
create table tmp01 as with tmp as ( select 1 as id from dual union all select 2 from dual union all select 3 from dual union all select null from dual)select * from tmp;create table tmp02 as with tmp as ( select 1 as id from dual union all select 2 from dual union all select null from dual)select * from tmp;select idfrom tmp01 where id not in ( select id from tmp02 );
2. 在使用not exitis常常碰到类似的查询not exists ( select 1 from tmp02 where tmp02.id=tmp01.id )或者not exists ( select null from tmp02 where tmp02.id=tmp01.id ),其实它们的结果是一样的,都是返回t1表与t2表的差集
SQL> select id,CASE WHEN ID IS NULL THEN 'id is null' ELSE 'id is not null' END "id null" from tmp01 where not exists ( select 1 from tmp02 where tmp02.id=tmp01.id ); ID id null---------- -------------- id is null 3 id is not nullSQL> select id,CASE WHEN ID IS NULL THEN 'id is null' ELSE 'id is not null' END "id null" from tmp01 where not exists ( select NULL from tmp02 where tmp02.id=tmp01.id ); ID id null---------- -------------- id is null 3 id is not nullSQL> select id,CASE WHEN ID IS NULL THEN 'id is null' ELSE 'id is not null' END "id null" from tmp01 where not exists ( select 'c' from tmp02 where tmp02.id=tmp01.id ); ID id null---------- -------------- id is null 3 id is not null
0 0
- not exists 与 select null,select 1的作用
- select 1 与 select null
- select 1 与 select null
- select not exists
- SQL Select 1 与 Select null 的理解
- not exists(select 1 什么意思
- select null与select 1区别
- SQL笔记-select 1与select null
- select 1 & select null
- where exists (select 1 from 中null=null时遇到的实际问题
- select 1的作用
- MySQL对CREATE TABLE IF NOT EXISTS SELECT的处理
- table does not exists,select 1 from tablename limit 1
- exists 和 select 1 from
- in,exists和not exists ,not in与null的一些关系记载
- in,exists和not exists ,not in与null的一些关系记载
- select函数的作用!
- select()函数的作用
- 黑马程序员——设计模式
- Myeclipse 项目打war包
- jdk 安装验证
- centos VNC服务器与VNC客户端配置
- 大话设计 之结构型模式
- not exists 与 select null,select 1的作用
- 用Eclipse + CDT + MinGW做Windows编程第二部分:Windows编程、面向对象程序设计
- wpfdatagrid样式
- Xcode问题
- Android Bitmap 防止OOM及其他操作
- 用Eclipse + CDT + MinGW做Windows编程第四部分:将可重用的部分做成静态库
- 四六级短期突击对策
- find -perm 里的 + -的含义
- PAGE_MASK判定addr是否是4096倍数