php - 构建MySQL查询从3个表插入数据到4.表

标签 php mysql

我有 3 个源表和 1 个目标表。我想将数据从源表复制到从 1.table->2.table->3.table->4.table 链接的目标表。
这是一个例子:

table1: 
| id | column1 | column2 | column3 | column4 |
|  1 | Asia    |  China  |         |         |

table2:  
| id | columna | columnb | columnc | columnd |
|  1 |    1    | Fruits  |         |         |

table3:  
| id | columnz | columy  | columnx | columnw |
|  1 |    1    |  Sweet  |         |         |

table4:  
| id | columnA | columnB | columnC | columnD | columnE | columnF | columnG |
|  1 |    1    |         |         |         |         | Yangmei | http:// |

我需要这个结果:

table4:  
| id | columnA | columnB | columnC | columnD | columnE | columnF | columnG |
|  1 |    1    | Asia    |  China  | Fruits  |  Sweet  | Yangmei | http:// |

组名和1.subgroup在table1的column1和column2下,2.subgroup在table2的columnb where columna = table1 id,3.subgroup在table3的columnb where columnz = table2 id,文章中table4 columnF 和 columnG 中的文章 url,其中 columnA = table3 id。

非常感谢您的帮助。

最佳答案

您可以尝试这样的操作,这可能会解决您的问题:

insert into table4 (cola,colb...)
values((select cola from tab1),(select cola from tab2)...)

我还没有检查代码,但我认为这会有所帮助。

关于php - 构建MySQL查询从3个表插入数据到4.表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29597967/

相关文章:

php - 在 PHP/索引 sitemap.php 上的多个站点地图树中吐出超过 50000 行的站点地图策略

php - 在数据库中搜索确切的词(不区分大小写)

mysql - CONCAT_WS 在 MYSQL 中的结果中返回每个后续列之前的第一列

mysql - 查询子索引是否有效

javascript - 如何自动更新html内容?

php - Mysql 交替工作日

php - 图片库与数据库配合?

c++ - 错误 : Can't connect to Mysql server on '' (10055)

mysql - IN operator caluse 具有 NULL 值似乎有效

php - Twitter Typeahead 标签从 MySQL 获取数据