Continue to ask MySQL query statement: Multi-table union query, how to limit the right table if there is a corresponding record to add a specific where limit or limit restrictions, and vice versa

Source: Internet
Author: User
Title

6 Table union query, the current use is still a LEFT join B right join C to a LEFT join D to a LEFT join E to a LEFT join F such

In order to ensure that each record in table A is found in the BCEDF table, there are only a few conditions to add.

However, after the restrictions such as where f.aaa in (0, 1, 2, 3) are added, the results of the query are all of the corresponding records in the F table.

I hope we can find out how to modify the statement without the corresponding record in F table.


Another question to ask is that if you add such a condition, there are still more than one becdf in the table, can you limit the number of entries in this SQL statement, such as the F table, to check only the latest, to prevent a table record from repeating in the results


Reply to discussion (solution)

A result needs to be connected through 6 tables, it should be said that your table design has a problem
Several transition tables can be formed by association keys to reduce the impact between tables

6 Table Query, this produces how much Cartesian product ah, anyway, I was stuck dead

Because you want to generate a real-time report ... So the business involved more ...

Of course, this must be a problem with the pre-design, but there's no way to reinvent it.

1, I have said above, the query to create a transition table, and then the Transition table query
2, through the view of the original unreasonable design into a reasonable design, query views for

Resolved add f.id is null

  • 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.