【发布时间】:2019-07-26 03:18:38
【问题描述】:
我有两个方案。当然,每个方案都有不同的名称。但是两种方案中的表和每个表的字段具有相同的名称。
我想从第一个方案的表中查询数据,以将结果插入到第二个方案表中。
问:这可能吗?
我的小测试给了我语法错误,但不清楚到底出了什么问题。
我在第二种方案中的查询类似于这个简单的查询:
INSERT INTO table1 (column1, column2, column3, ...)
SELECT table1.column1
FROM scheme1.table1
第一行(插入)在 scheme2 中。第二行和第三行来自方案1。但这不起作用。
问:如何从两个具有相同表名和表字段名的不同方案中进行查询。
附:我知道这种设计选择并不理想。但我发现自己处于这种情况。它不是一个长期的生产数据库,而是用于研究数据。我需要从这两个方案中查询。
编辑:
插入到 test2.t1.col1 select t1.col1 from test1.t1;st query is:
insert into test2.t1.col1
select t1.col1 from test1.t1;
方案是:test1 和 test2
这些表格是:test1.t1 和 test2.t1
列是:test1.t1.col1test2.t1.col1
查询结果为:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.col1 select t1.col1 from test1.t1' at line 1
【问题讨论】:
-
在您的 from statemetn 中,您将架构引用为 schema1.table1,但在插入时您没有架构。您需要为您的插入语句创建 schema2.table1
标签: mysql database database-design mysql-workbench