Questions tagged [on-duplicate-key]

ON DUPLICATE KEY UPDATE is an SQL feature in MySQL which allows a row to be updated instead on inserted in an INSERT query, if it would otherwise attempt to create a duplicate key in a unique index.

ON DUPLICATE KEY UPDATE is an SQL feature in MySQL which allows a row to be updated instead on inserted in an INSERT query, if it would otherwise attempt to create a duplicate key in a unique index.

Example:

INSERT INTO t (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;  

So, if c is a unique column in table t, and the key 3 already exists for column c, then MySQL executes the update c=c+1 rather than inserting.

This feature eliminates the need for an extra query check for duplicate key values.

Reference: MySQL Manual

305 questions
-2
votes
3 answers

mysql crash with update on duplicate key query

Recently, a production MySQL server has crashed occasionally after upgrade from 5.5 to 5.7.19. The following is the stack trace in error log and the table related to the problematic query。I had turned on the general log and every time MySQL crashed.…
zczhuohuo
  • 169
  • 1
  • 13
-2
votes
1 answer

MySql - On Duplicate Key

I have a table: Saves ----- UserId (int primary key) Save (blob) SaveBackup (blob) This is populated with this: Saves(22, 'xyz', '') I submit the following: $stmt = $db->prepare("INSERT INTO Saves (UserId, Save, SaveBackup) " …
Rewind
  • 2,554
  • 3
  • 30
  • 56
-2
votes
1 answer

How to find duplicate data during insertion in mysql ?

I want to find duplicate data with this query which may occur during insertion. Is there any way to find it? INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c') ON DUPLICATE KEY UPDATE tag=tag;
Pankti Shah
  • 35
  • 1
  • 7
-2
votes
1 answer

data not coming in proper order from table using php

I am trying to insert data from feed into the database using Zend and also adding a column date_updated in table so that whenever the article in feed is updated the column also gets updated. But the problem is, the first article is being inserted…
-2
votes
6 answers

PHP code in counting duplicate letters in two words

hi there i'm a newbie in php and i would like to ask how to write a code that will out put the number of duplicated letters in two words. for example: "apple" and "ball" in overall it has a 7 same letters (a,a,p,p,l,l,l) thank you in advance :)
Christine Javier
  • 31
  • 1
  • 2
  • 6
1 2 3
20
21