![](/img/trans.png)
[英]How to merge two tables having the same column in both the tables in order to identify the discrepancies in MySQL?
[英]How to merge two tables with same values in a column
我有两个表,Table1和Table2。
Table1具有列“ ID ”,“ Date ”, Table2具有列“ ID ”,“ Cost ”。
现在,我希望将这两个表合并到一个新表Table3中的方式,其中列“ ID ”,“ 日期 ”,“ 成本 ”是成本和日期在同一行中,在Table2和Table1中具有相同的ID分别。
简而言之,我想将两个表相对于列粘合,在本例中为“ ID ”。
我已经研究过像INSERT INTO TABLE
这样的语句但是我无法让它工作。
您可以对两个源表之间的连接结果执行insert-select:
CREATE TABLE table3 AS
SELECT table1.id AS id, date, cost
FROM table1
JOIN table2 ON table1.id = table2.id
请使用下面的SQL进行合并
insert into table3(id,date1,cost)从table1 a,table2 b中选择a.id,b.date1,a.cost,其中a.id = b.id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.