`
ymanyang
  • 浏览: 4802 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
社区版块
存档分类
最新评论

SQL Exists Condition

 
阅读更多

The exists condition is considered to be met if the subquery returns more than one row. It always used to test whether relevant recrods exist and filter out those extraneous results.

The common case is that A object and B object have an association, which contains all the relationships between A and B records, and you can utilize this association object to find records of A without relationship with B. Below is a sql statement in ORACLE to select specific A records which have relationship with B:

 

 

SELECT a.id FROM a, association where association.aid= a.id and exists (SELECT NULL FROM b WHERE b.id=association.bid)

NULL keyword is used to increase performance.

分享到:
评论

相关推荐

    详解SQL EXISTS 运算符

    SQL EXISTS 语法 SELECT column_name(s) FROM table_name WHERE EXISTS (SELECT column_name FROM table_name WHERE condition); 演示数据库 在本教程中,我们将使用 RUNOOB 样本数据库。 下面是选自 “Websites” ...

    2009达内SQL学习笔记

    多数DBMS不需要在单条SQL语句后加分号,但特定的DBMS可能必须在单条SQL语句后加分号。 SQL语句的最后一句要以 “;”号结束 二、写子句顺序 Select column,group_function From table [Where condition] ...

    Sql for mysql

    3.5 Downloading SQL Statements from the Web Site . . . . . . . . . . 38 3.6 Ready? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 CHAPTER 4 SQL in a Nutshell ...

    SQL语法大全

    SQL语法大全 SQL语法大全 1. ASP与Access数据库连接: dim conn,mdbfile mdbfile=server.mappath("数据库名称.mdb") set conn=server.createobject("adodb.connection") conn.open "driver={microsoft access ...

    微软内部资料-SQL性能优化5

    In a nonclustered index, the leaf level contains each index key, plus a bookmark that tells SQL Server where to find the data row corresponding to the key in the index. A bookmark can take one of two ...

    ORM及代码生成器C#源码(最新版V4.5.8.5、非常适于ASP.NET MVC)

    protected static bool Exists(string condition); public bool ExistsById(); public bool ExistsByPK(); protected static List<T> Find(PagingArg pagingArg, params string[] propertyNames); protected ...

    ORM及代码生成器和插件C#源码(DBFrameworkV4.5.3)

    protected static bool Exists(string condition); public bool ExistsById(); public bool ExistsByPK(); protected static List<T> Find(PagingArg pagingArg, params string[] propertyNames); protected ...

    ORM及代码生成器C#源码(2012最新版Kenly.DBFramework4.6.5.5)

    protected static bool Exists(string condition); public bool ExistsById(); public bool ExistsByPK(); protected static List<T> Find(PagingArg pagingArg, params string[] propertyNames); protected ...

    [php]mysql数据库操作——DB类

    DB类<?... charset=utf-8'); ... ... //禁止直接访问本页 ...※※※※※※※※※※※※※※※※※※※※※※※※※※※... $sql="SELECT {$Fileds} FROM `{$Table}` {$Condition}"; return $this->query($sql); } // 只查询...

    用 S Q L 代 码 谢存储过程

    用SQL拼代码的 if exists(select * from sysobjects where name='NewClassID') drop proc NewClassID go create proc NewClassID @cID varchar(20) output, @period varchar(1), @type varchar(2)='A', @addr ...

    Oracle事例

    select constraint_name, constraint_type,search_condition, r_constraint_name from user_constraints where table_name = upper(\'&table_name\') select c.constraint_name,c.constraint_type,cc.column_name...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

     数据查询语言 (Data Query Language, DQL) 是SQL语言中,负责进行数据查询而不会对数据本身进行修改的语句,这是最基本的SQL语句。例如:SELECT(查询)  数据控制语言Data Controlling Language(DCL),用来...

    mysql心得分享:存储过程

    use test; drop table if exists t8; CREATE TABLE t8(s1 INT,PRIMARY KEY(s1));...DECLARE oh_no condition for sqlstate '23000'; #DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET @X2=1; declar

    win 3.11 for workgroup tcpip支持

    One such condition commonly encountered is when a network connection is attempted from the File Manager. The result is that the name is reported as 'not resolved' even if the name exists in LMHOSTS ...

    整理后java开发全套达内学习笔记(含练习)

    exist 存在, 发生 [ig'zist] '(SQL关键字 exists) extends (关键字) 继承、扩展 [ik'stend] false (关键字) final (关键字) finally (关键字) fragments 段落; 代码块 ['frægmәnt] FrameWork [java] 结构,...

Global site tag (gtag.js) - Google Analytics