sql 子查询中的exists 和 in
2014-12-23 19:15
337 查看
exists貌似不是标准sql
exists()是用来判断括号里面的值或者结果集是否为null的,
返回的是bool类型的,比如select * from a where exists(select
1 from b where id=a.id), 同(select id from b where
id = a.id)
如果select 1 from b where id=a.id这一句能查出来数据,那么查出来的a表中的数据是这样写是一样的
:select * from a where id in(select id from b);只不过在用in查询的时候要进行全表查询,效率没有exists高
如果子查询中要处理的少,用in //where t.id
in ('040000000000PS','040000000000QV')
查询结果多,或条件多于1个用exists
select * from J_YHDA t
where exists (select null from dual) //oracle中这样写. 在子查询中使用 NULL
仍然返回结果集 等同select all .没where
别的数据库好像这样写也行
select * from J_YHDA t
where exists (select null )
select * from TableIn where exists(select BID from TableEx where
BNAME=TableIn.ANAME)
select * from TableIn where ANAME in(select BNAME
from TableEx) //这俩结果一样
(第一个相关,第二个非相关, 效率不好说)
exists()是用来判断括号里面的值或者结果集是否为null的,
返回的是bool类型的,比如select * from a where exists(select
1 from b where id=a.id), 同(select id from b where
id = a.id)
如果select 1 from b where id=a.id这一句能查出来数据,那么查出来的a表中的数据是这样写是一样的
:select * from a where id in(select id from b);只不过在用in查询的时候要进行全表查询,效率没有exists高
如果子查询中要处理的少,用in //where t.id
in ('040000000000PS','040000000000QV')
查询结果多,或条件多于1个用exists
select * from J_YHDA t
where exists (select null from dual) //oracle中这样写. 在子查询中使用 NULL
仍然返回结果集 等同select all .没where
别的数据库好像这样写也行
select * from J_YHDA t
where exists (select null )
select * from TableIn where exists(select BID from TableEx where
BNAME=TableIn.ANAME)
select * from TableIn where ANAME in(select BNAME
from TableEx) //这俩结果一样
(第一个相关,第二个非相关, 效率不好说)
相关文章推荐
- sql 子查询中的exists 和 in
- sql查询关建字之-exists, in. all, any, some
- 比较Oracle SQL中的IN & EXISTS
- SQL查询中in和exists的区别
- Oracle sql"NOT IN"语句优化,查询A表有、B表没有的数据
- Entity SQL Language 三 Where/Exists/In/Like/参数及外键查询
- MSSQL 使用SQL语句查询数据库…
- SQL查询中in和exists的区别分析
- Linq to SQL 语法查询(子查询 & in操作 & join )
- 比较Oracle SQL中的IN & EXISTS
- sql查询语句中 in和 exists的区别与性能比较
- 【SQL】查询语句中in和exists的区别
- SQL - 查询条件 In与exists的区别
- SQL查询中in和exists的区别分析
- 比较Oracle SQL中的IN & EXISTS
- Linq to SQL 语法查询....子查询 & in操作 & join
- 比较Oracle SQL中的IN & EXISTS
- hive java.sql.SQLException: Table/View 'PARTITION_STATS_V2' already exists in Schema 'APP'.
- Linq to SQL 语法查询(子查询 & in操作 & join )
- Linq to SQL 语法查询(子查询 & in操作 & join )(转载)