【问题标题】:MYSql Code to Display data from two tables into Single oneMYSql 代码将两个表中的数据显示为单个表
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2022-01-03
    • 1970-01-01
    • 2015-01-17
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    相关资源
    最近更新 更多