MySQL INSERT SELECT-复制行 [英] MySQL INSERT SELECT - Duplicate rows
本文介绍了MySQL INSERT SELECT-复制行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这样执行INSERT SELECT查询:
I want to do an INSERT SELECT query like this:
INSERT INTO `tableName` (SELECT * FROM `anotherTable`)
问题是,当它发现重复值时,整个过程将停止,真的我只希望它继续并跳过重复项.
The problem is when it finds a duplicate value the whole thing will stop, really I just want it to continue and skip the duplicates.
我知道我可以使用-f参数通过cmd行来执行此操作,但是我想使用PHP来执行此操作. PHP mysql_ *函数中的某处是否存在强制或忽略错误选项?
I know I can do this via the cmd line by using the -f parameter to force it, but I want to do it with PHP. Is there a force or ignore errors option somewhere in the PHP mysql_* functions?
推荐答案
您需要添加ON DUPLICATE KEY IGNORE:
You need to add ON DUPLICATE KEY IGNORE :
INSERT INTO `tableName` (SELECT * FROM `anotherTable`) ON DUPLICATE KEY IGNORE
此处的信息-> http://dev.mysql.com/doc/refman/5.5/en/insert.html
这篇关于MySQL INSERT SELECT-复制行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文