Get the fastest difference for MySQL two tables

Source: Internet
Author: User

MySQL is nothing more than a subquery and two ways of connecting.

The first table is Table1, the second is table2, and Table1 contains table2.

SQL is:

1 //Sub-query2 SelectTable1.id fromtable13   where  not exists 4(Select 1  fromtable25      whereTable1.id=table2.id6     );7  8 //External Connection9 SelectTable1.id fromtable1Ten    Left Jointable2 One    onTable1.id=table2.id A whereTable2.id is NULL;

There are similar examples in high-performance MySQL, see "When a correlated subquery is good" section. It gives the data, the outer connection to be fast.

Also, to be the fastest, it is best to do a difference between the primary keys of the two tables, so that only the index is overwritten, it will be faster.

Get the fastest difference for MySQL two tables

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.