i have a members table that contain 3 field as a foreign key for 3 tables
so i want to join between them is that possible ??
member table :
each field is the foreign key for a table
governorate table :
district table :
village table :
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
).
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.