Analysis of exists and in

Source: Internet
Author: User
Exists and in are doing the same thing. Why do we need to solve two problems? in fact, they are efficiency problems. For example, the following two examples 1. select * fromt1whereexists (selectXfromt2wheret1. at2.a) PS: replace 'x with any other regular bright characters, such as the number character "etc. 2. select * fromt1wheret1. ai

Exists and in are doing the same thing. Why do we need to solve two problems? in fact, they are efficiency problems. For example, the following two examples 1. select * from t1 where exists (select 'x' from t2 where t1.a = t2.a) PS. 2. select * from t1 where t1.a I

Exists and in do the same thing, so why do we need to get two more? It is actually a matter of efficiency.

For example, the following two examples

1. select * from t1 where exists (select 'x' from t2 where t1.a = t2.a)

PS: The 'X' here can be changed to any other regular bright, such as the numeric character etc.

2. select * from t1 where t1.a in (select t2.a from t2)

When exists is used, oracle first executes the primary query and then the subquery. Therefore, when the t1 data volume is small and the t2 data volume is large, the efficiency is high,

When in is used, oracle will first execute the subquery and then the primary query. Therefore, when the t2 data volume is small, the efficiency is high when the t1 data volume is large.

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.