Two millions data sheets, questions about joint queries

Source: Internet
Author: User
Two millions data sheets, the problem of joint query
Two data tables, a, B.
A, B table has two fields: Exp_code, CODE;
Now to find out a, B table in the Exp_code field equals ' R8_002_xz, and Exp_code not the same record, with the following statement, if two tables Exp_code record tens of thousands of cases, basically the crash, not to mention to millions. Ask how to improve.

SELECT * from a where exp_code= ' r8_002_xz ' and CODE not in (select CODE from B)


------Solution--------------------
SELECT * from a where exp_code= ' r8_002_xz ' and CODE not in (select CODE from B)

=======================================================

SELECT * from a LEFT join B on A.code=b.code
where a.exp_code= ' R8_002_xz ' and b.code is null

Look at your code on the index, such as no, build index, Exp_code also built


------Solution--------------------
Upstairs positive solution, but for millions record database is still slow, can be limited by limit
------Solution--------------------
SELECT * from a where exp_code= ' r8_002_xz ' and code not exist (select code from B where exp_code!= ' R8_002_xz ')
The syntax above may be a bit problematic, but the logical relationship should be right.
Requires:version> 4.1 to support subqueries.
------Solution--------------------
Is this what you asked for?
SELECT * from a LEFT join B on A.code=b.code and A.exp_code=b.exp_code
where a.exp_code= ' r8_002 ' and b.code is null


------Solution--------------------
Nested select is less efficient, try to use inner join, left join instead
------Solution--------------------
It's wrong. Change to the following:
SELECT * from a where exp_code= ' r8_002_xz ' and Code not in (select code from B where exp_code!= ' r8_002_xz ');
Or
SELECT * from a where exp_code= ' r8_002_xz ' and NOT EXISTS (select code from B where exp_code!= ' R8_002_xz ' and a.code=b. code);



------Solution--------------------
SELECT * from a LEFT join B on A.code=b.code and A.exp_code=b.exp_code and B.code is null

All you need to do is to find the records in a that are not in B, and then press B to append the structure!

Hard, "Farmer" peer!

------Solution--------------------
Hahaha .... Met with ...
  • 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.