MySQL在重复键上插入更新多个值 [英] MySQL insert on duplicate key update multiple values

查看:63
本文介绍了MySQL在重复键上插入更新多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im当前将大量(100k +)行插入表中,如下所示:

Im currently inserting a large amount (100k+) of rows into a table as follows:

//START of a loop

$updatedData[] =  '(
                      "'.$field_1.'",
                      "'.$field_2.'",
                      "'.$field_3.'"
                   )';
//END of loop

$updatedData = implode(',', $updatedData);

$query = "INSERT INTO table (field_1,field_2,field_3) VALUES $updatedData";

这一切都很好,但是现在我正在寻找一种方法来更新行,而不是如果$ field_1和$ field_3是重复的,则不插入新行.

This is all working perfectly, but now I'm looking for a way to update a row instead of insert a new one if $field_1 and $field_3 are duplicates.

推荐答案

只需对您的$ updatedData进行计数.

Just take counter of your $updatedData.

并以循环方式运行,即可按需运行.

And run that in loop this will run as you want.

祝一切顺利.

汉字

这篇关于MySQL在重复键上插入更新多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆