0
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 查询帮助来解决这个问题

4

2 回答 2

1

这是未经测试的,但您可能想尝试这样的事情,并查找内部连接

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`
于 2013-07-19T19:27:37.667 回答
0
SELECT location.id, city.city, state.state,country.country
FROM location,city,state,country
WHERE location.country_id = country.id
AND location.city_id = city.id
AND location.state_id = state.id
于 2013-07-19T19:29:15.273 回答