SQL statement for multiple associated tables-php Tutorial

Source: Internet
Author: User
I do not know the description of the SQL statements for multiple associated tables.



Reply to discussion (solution)

I do not know whether the description is clear or not.

Select * from a, B, c where. KSBH = C. KSBH and. XMBH = B. XMBH where B. TJDJBH = '000000' and. KSBH = '01' // The description is not clear enough.

Select * from a, B, c where. KSBH = C. KSBH and. XMBH = B. XMBH where B. TJDJBH = '000000' and. KSBH = '01' // The description is not clear enough.



The statement you provide has two where

Let's analyze it first.
Table 4 communicates with the other three tables
Table 4 itself expresses:
What health check items are included in a comprehensive project (ZHBH, XMBH)
What health check items are included in a department (KSBH, XMBH)
What comprehensive projects are included in a department (KSBH, ZHBH)
The name of the health check item can be found in Table 4 XMBH.
Similarly, the name of the health check item can be found in Table 4's KSBH.
The four types of KSBH in table correspond to XMBH one by one, so the KSBH in Table 1 is redundant.
Similarly, the KSBH in Table 3 is redundant.
In table 2, the user does a real check (XMBD) and does not need to care about which ZHBH the XMBH belongs.
Therefore, ZHBH in table 2 is redundant.
From the table, we can know (through XMBH in Table 4 and XMBH in table 2)
An XMBH is involved by TJDJBH.
A zhbh is involved by TJDJBH.

The next thing should be difficult, right?

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.