如果有共同点,如何将数据从表1插入表2?

时间:2019-03-25 11:46:41

标签: mysql sql

我在MYSQL的同一数据库中有2个表,我想将table1中的columnA插入table2中的columnA中,而我的条件是table1.name等于table2.name。我尝试过但是没用

INSERT INTO Table2 (solId, openTime, closingTime, guid)  
SELECT solId, openTime, closingTime, guid
FROM Table1
WHERE Table2.name = Table1.name;

1 个答案:

答案 0 :(得分:2)

您可能需要update

update table2 t2 join
       table1 t1
       on t1.name = t2.name
    set t2.solId = t1.solId,
        t2.openTime = t1.openTime,
        t2.closingTime = t1.closingTime,
        t2.guid = t1.guid;