我在数据库中有这些表:
country:
id country
------------------
1 USA
2 Brazil
和细分表:
id country
------------------
1 USA
2 Brazil
我有第三张表:
Id segment_id country_id
其中segment_id是段表
中id的外键和country_id是国家/地区表中id的外键
myquestion是:
如何从具有3个表的内连接的其他表中进行选择,
我需要显示国家/地区的名称加上每个国家/地区在下拉菜单中显示所有细分如果有人可以帮助我
谢谢你
答案 0 :(得分:0)
你只是试试这个
$sql = select * from third_table
inner join country on third_table.country_id = country.id
inner join segment on third_table.segment_id = segment.id
$res = mysql_query($sql);
'or'
select * from TableA A
inner join TableB B on A.Column=B.Column
inner join TableC C on A.Column=C.Column
答案 1 :(得分:0)
SELECT *
FROM third_table t
INNER JOIN country c ON t.country_id = c.country_id
INNER JOIN segment s ON t.segment_id = s.segment_id
答案 2 :(得分:0)
尝试此查询..这将有助于您创建列表
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