简体   繁体   English

使用内连接和4个表是可能的

[英]using inner join and 4 tables is that possible

i have a members table that contain 3 field as a foreign key for 3 tables 我有一个成员表,其中包含3个字段作为3个表的外键

so i want to join between them is that possible ?? 所以我想加入他们之间是可能的吗?

member table : 会员表:

  • governorate
  • district
  • village

each field is the foreign key for a table 每个字段都是表的外键

governorate table : 省表:

  • governorate_id governorate_id
  • governorat_name governorat_name

district table : 分区表:

  • district_id district_id
  • district_name district_name

village table : 村桌:

  • id ID
  • village_name village_name

can i do it in one query ???? 我可以在一个查询中做到吗????

Yes you can. 是的你可以。

SELECT  b.governorat_name,
        c.district_name,
        d.village_name
FROM    member a
        INNER JOIN governorate b
            ON a.governorate = b.governorate_id
        INNER JOIN district c
            ON a.district = c.district_id
        INNER JOIN village d
            ON a.village = d.id

To further gain more knowledge about joins, kindly visit the link below: 要进一步了解联接,请访问以下链接:

The query uses INNER JOIN in which results should have atleast one matching record on every parent table ( governorate , district , village ). 该查询使用INNER JOIN ,其中结果应该在每个父表( governoratedistrictvillage )上至少有一个匹配记录。

When columns are nullable and you want to show all records on table member table whether it has no matching record on the parent table, use LEFT JOIN instead if INNER JOIN . 当列可以为并且您希望在表member表上显示它是否在父表上没有匹配记录时,如果是INNER JOIN ,则使用LEFT JOIN INNER JOIN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM