MySQL INSERT SELECT - Duplicate rows

后端 未结 2 1529
孤城傲影
孤城傲影 2021-01-23 23:45

I want to do an INSERT SELECT query like this:

INSERT INTO `tableName` (SELECT * FROM `anotherTable`) 

The problem is when it finds a duplicate

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 00:16

    You need to add ON DUPLICATE KEY IGNORE :

    INSERT INTO `tableName` (SELECT * FROM `anotherTable`) ON DUPLICATE KEY IGNORE
    

    Info here-> http://dev.mysql.com/doc/refman/5.5/en/insert.html

提交回复
热议问题