【发布时间】:2016-06-30 11:48:32
【问题描述】:
我有两张表States 和Cities。 在teststates表中:有不同国家的状态数据
代码列具有与其关联的状态的 id
在城市表中: 区域列与 teststates 表中的代码列具有相同的 id。
要求: 我希望 mysql 中的代码从 teststates 表列中获取 id 并将其替换为 testcities 表中的 region 列,因为我只需要 testcities 表中的城市名称和区域两列。请帮帮我!
【问题讨论】:
-
您想要一个 SELECT 查询还是更新查询。
-
我想要更新查询,首先从 teststates 表中获取区域,然后更新 testcities 表中的区域列。
-
你想如何从测试状态中获取区域??
-
teststates 中的 code 列是指 testcities 表中的 region 列,我想先从 states 表中读取它并更新 testities 表中的 region。我想通过嵌套循环之类的代码来做到这一点,因为我有很多表,并且手动执行同一件事会花费很多时间。
标签: mysql database-design