Location table
-----------------------------------------------
|location.id|country.id|state.id|city.id|
Country
-----------------------------------------------
|country.id|country|
State
-----------------------------------------------
|state.id|state|
City
-----------------------------------------------
|city.id|city|
现在我有了location.id,我需要从location.id中一次性获取国家、城市、州名称。
需要 Sql 查询帮助来解决此问题
最佳答案
这尚未经过测试,但您可能想尝试类似的操作,并查找 inner joins
select * from locations
inner join Country on `Country`.`country.id` = locations.`country.id`
inner join State on `State`.`state.id` = locations.`state.id`
inner join City on `City`.`city.id` = locations.`city.id`
关于mysql - 如何从mysql中的3个表中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753911/