[Oracle] exists 和 not exists
簡單用兩個例子說明一下exists和not exists的用法.
SQL> select * from tt2;
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
1098 SEQUENCE
1279 PACKAGE
1300 VIEW
6 rows selected.
SQL> select * from tt1;
ID NAME
---------- --------------------
100 EDITION
116 TABLE
117 SYNONYM
SQL> select * from tt2 where name in(select name from tt1);
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
SQL> select * from tt2 where exists (select name from tt1); #tt1查詢出來的為true,故tt2所有值返回
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
1098 SEQUENCE
1279 PACKAGE
1300 VIEW
6 rows selected.
SQL> select * from tt2 where exists (select name from tt1 where tt1.name=tt2.name); #tt1連線tt2後查詢出來的為true,故tt2所有值返回
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
SQL> select * from tt2 where not exists (select * from tt1);
no rows selected
SQL> select * from tt2 where not exists (select * from tt1 where tt1.name=tt2.name);
ID NAME
---------- ----------------------------------------
1279 PACKAGE
1300 VIEW
1098 SEQUENCE
SQL> select * from tt2;
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
1098 SEQUENCE
1279 PACKAGE
1300 VIEW
6 rows selected.
SQL> select * from tt1;
ID NAME
---------- --------------------
100 EDITION
116 TABLE
117 SYNONYM
SQL> select * from tt2 where name in(select name from tt1);
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
SQL> select * from tt2 where exists (select name from tt1); #tt1查詢出來的為true,故tt2所有值返回
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
1098 SEQUENCE
1279 PACKAGE
1300 VIEW
6 rows selected.
SQL> select * from tt2 where exists (select name from tt1 where tt1.name=tt2.name); #tt1連線tt2後查詢出來的為true,故tt2所有值返回
ID NAME
---------- --------------------
100 EDITION
116 TABLE
280 SYNONYM
SQL> select * from tt2 where not exists (select * from tt1);
no rows selected
SQL> select * from tt2 where not exists (select * from tt1 where tt1.name=tt2.name);
ID NAME
---------- ----------------------------------------
1279 PACKAGE
1300 VIEW
1098 SEQUENCE
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2134035/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle中關於in和exists,not in 和 not existsOracle
- oracle中的exists和not exists和in用法詳解Oracle
- oracle中的exists 和not exists 用法詳解Oracle
- in/exists和not in/not exists執行效率
- [Oracle] minus 和 not exists比較Oracle
- ORACLE 中IN和EXISTS比較Oracle
- oracle exists and not existOracle
- exists和not exists及in和not in的用法與區別
- SQL中IN,NOT IN,EXISTS,NOT EXISTS的用法和差別SQL
- oracle中in和exists的區別Oracle
- (轉)ORACLE 中IN和EXISTS比較Oracle
- oracle 用EXISTS替代INOracle
- EXISTS、IN、NOT EXISTS、NOT IN用法區別
- In和exists使用及效能分析(二):exists的使用
- In和exists使用及效能分析(三):in和exists的效能分析
- (轉)ORACLE 中IN和EXISTS的區別Oracle
- Oracle中exists和in的效能差異Oracle
- in 和 exists區別
- Oralce 使用SQL中的exists 和not exists 用法詳解SQL
- 對IN & EXISTS NOT IN & NOT EXISTS的優化優化
- EXISTS、IN、NOT EXISTS、NOT IN的區別(ZT)
- oracle中的exists理解Oracle
- sql:delete if exists還是drop if exists?SQLdelete
- exists和連線方式
- in,exists和not exists ,not in與null的一些關係記載Null
- oracle in與exists 的區別Oracle
- 【SQL】existsSQL
- mysql 關於exists 和in分析MySql
- Exists和IN的原理解析
- ORACLE 9I not exists的bugOracle
- Oracle 中不使用NOT IN 和 NOT EXISTS的另一種方法Oracle
- 理解exists count
- 關於ORACLE MYSQL NOT IN和NOT exists需要注意的 NULL值OracleMySqlNull
- MySQL之in與existsMySql
- SQL語句中exists和in的區別SQL
- in和exists的一些區別
- SQL中IN和EXISTS用法的區別SQL
- oracle sql_not exists與null的測試OracleSQLNull