MYSql代码将两个表中的数据显示为单个表

时间:2016-03-15 06:54:04

标签: mysql database-design

我有两个表州和城市。 在teststates表中:有关于不同国家/地区的状态的数据enter image description here

代码列具有与之关联的状态的ID

在城市表中:       有一个region列,它与teststates表中的code列具有相同的id。 enter image description here

要求: 我希望mysql中的代码从teststates表列中获取id并将其替换为testcities表中的region列,因为我只想要两个列,即testcities表中的城市名称和区域。请帮帮我!

1 个答案:

答案 0 :(得分:0)

select a.name,b.region from teststates a,testcities b where a.country = b.country

这将返回两个表中国家/地区名称上的城市名称和地区名称列。