3个表之间的内部联接 [英] inner join between 3 tables

查看:86
本文介绍了3个表之间的内部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有这些表:

i have these table in database:

country:

id      country
------------------
1       USA
2       Brazil

和细分表:

id      country
------------------
1       USA
2       Brazil

我有第三张桌子:

Id segment_id country_id

其中segment_id是细分表中ID的外键

where segment_id is a foreign key of id in segment table

and country_id是国家表中ID的外键

and country_id is a foreign key of id in country table

我的问题是:

如何从具有3个表的内部联接的另一个表中进行选择,

how to select from the other table with inner join of the 3 tables,

我需要显示国家/地区的名称,并且每个国家/地区都应在下拉菜单中显示所有细分,如果有人可以帮助我

i need to show the name of the country plus for every country show all the segments in a dropdown menu if anyone could help me

谢谢你

推荐答案

尝试此查询.这将帮助您创建列表

try this query.. this will help you to create list

select countrysegments.id as countrysegmentsID, country.country as countryName,
segment.country as segmentName
from countrysegments 
       inner join country on countrysegments.country_id  = country.id
       inner join segment on countrysegments.segment_id = segment.id

这篇关于3个表之间的内部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆