MySQL INSERT SELECT - Duplicate rows

后端 未结 2 1497
孤城傲影
孤城傲影 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

    0 讨论(0)
  • 2021-01-24 00:19

    Use INSERT IGNORE

    INSERT IGNORE INTO `tableName` (SELECT * FROM `anotherTable`) 
    
    0 讨论(0)
提交回复
热议问题