Exists () and in () Applications

Source: Internet
Author: User


Exists () and in () Applications 1. example: emp table: Address Numberbj 40bj 30fj 20fj 10www.2cto.com dept table: Bearing AddsNO bjSO fj (1) exists () Application select sum (Number) from emp where exists (select * from dept where Bearing = 'so') the output result is: 100 www.2cto.com does not seem to match. The answer is correct, because exists is used to determine whether exists exist. If the query result in exists (query) returns true, otherwise false. Not exists is the opposite. When exists is used as the where condition, it first queries the primary query before where, and then substitutes the results of the primary query into the query of exists for judgment. If it is true, It outputs the results of the current primary query, otherwise, no output is made. Not exists is opposite to exists. (2) the output result of the in application select sum (Number) from empwhere Address in (select Adds from dept where Bearing = 'so') is: 30 in is used to determine the value contained in a field. Multiple values are allowed in the where clause. Not in is an excluded value. Syntax: select * from table 1 where field 1 in (val, val ,.....) www.2cto.com select * from empwhere adds not in (select Adds from dept where Bearing = 'so '); select * from empwhere not exists (select Adds from dept where Bearing = 'so' and emp. address = dept. adds) 2. the Efficiency Value of in and exists is not absolute. In is suitable for the select * from emp where deptid in (select id from dept) of small external tables to: select * from emp, (select distinct id from dept) dept where emp. deptid = dept. id; exists is suitable for select * from emp where exists (select id from dept where dept. id = emp. deptid) to: www.2cto.com for deptid in (select * from emp) loop if (exists (select id from dept where id = emp. deptid) then output the record! End if end loop

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.