mSQL database in and exists usage comparison

Source: Internet
Author: User

Exists: Usage: SELECT * FROM table1 where exists (SELECT * from table2 where table1.id = table2.id)
Returns records with the same ID in Table1 and table2 (double loop) result and in syntax, thinking differently,
In:select * FROM table1 where ID in (select ID from table2)

2 ideas are different: exists: first get each table1 data, and then get the ID field, go to table2 table to find the corresponding value, find the description matches the condition
In: The ID probability is obtained first, and then the table2 data is retrieved to determine whether the current ID is within the ID collection

For in: If the amount of data in the table2 is too large to use, because he needs to find out and store so much data first, it is expensive and can be used exists

mSQL database in and exists usage comparison

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.