Continue to consult mysql Query statement: multi-table joint query, how to limit the right-side table if there is a corresponding record, then add a specific where limit or limit, otherwise no limit

Source: Internet
Author: User
Continue to consult the mysql Query statement: multi-table joint query, how to limit the right table if there is a corresponding record, then add a specific where limit or limit, otherwise there is no limit, as shown in the question

6 Table join queries. Currently, a left join B left join c left join d left join e left join f is used.

To ensure that each record in Table a can only find one corresponding record in the bcedf table, some conditions must be added.

However, after a restriction such as where f. aaa in (0, 1, 2, 3) is added, all query results have corresponding records in table f.

How can I modify the statement if no corresponding record exists in table f?


In addition, if another question is asked, even if such a condition is added, the becdf table still has multiple records. can I limit this SQL statement to only query the latest one for table f, to prevent repeated records in Table a from appearing in the results


Reply to discussion (solution)

A query result needs to be connected through 6 tables. it should be said that there is a problem with your table design.
You can press the join key to create several transition tables to reduce the impact between tables.

6. what is the Cartesian product generated for table queries? I am stuck.

Because you want to generate real-time reports... so there are many businesses involved...

Of course, this is definitely a problem with the preliminary design, but there is no way to redo it now.

1. as I have mentioned above, a transitional table is generated before querying a transitional table.
2. use a view to convert an unreasonable design into a rational design, and query the view.

F. id is null

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.