MYSQL not-in sub-connection query does not have a value problem

Source: Internet
Author: User

The first few days in the project, do the data import, found not in and in the check out the number of bars is not complementary. ATABLE2 some of the records in ATABLE3 do not exist, but not in when the record is not found.

CREATE TABLE ATABLE2
("Mrid" VARCHAR2 (BYTE)
)

CREATE TABLE ATABLE3 "
("Mrid" VARCHAR2 (BYTE)
)

The query statements are as follows

Select COUNT (*) from Atable2 where Mrid is not in (select Mrid from Atable3), the query result is 0.

After several checks, the problem of not in and Null was found. There is a mrid null record in the Atable3 table, at which time not the in query does not have a value.

The modification scenario is as follows: adding non-null filtering in subqueries

Select COUNT (*) from Atable2 where Mrid not in (select Mrid from Atable3 where mrid are NOT null)

Complete!

The ps:count statistic function does not apply to null values and requires count (*).

MYSQL not-in sub-connection query does not have a value problem

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.