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
0
votes
1 answer

mysql_query ON DUPLICATE KEY UPDATE

I have problem, I would like to make update when hash is same. hash is unique at table. I cant find the right way to do this. mysql_query("INSERT INTO shop_product_search3_muokattu2 (id, hash, product_name, type, manufacturer,…
0
votes
1 answer

ON DUPLICATE KEY UPDATE half working

I have a shopping cart as a DB table called cart that stores records of items in each SaaS instances shopping cart. What I want to do, is that if a product is added to the cart for the a user and an identical record already exists, is to update the…
Arbiter
  • 486
  • 1
  • 8
  • 21
0
votes
1 answer

MySQL alternative to on duplicate key update

I'm trying to pull from multiple tables to insert into a table to create role assignments in moodle's database based on the categories that are created but I need it to update on duplicate key but I cant use ON DUPLICATE KEY UPDATE because the…
0
votes
2 answers

Oracle complex query: INSERT + SELECT CONNECT BY + ON DUPLICATE KEY

I have a table to count word occurences, WORD_COUNT(WORD, TOTAL), which is updated in a trigger over another table. This is done in a hierachichal query like this: Creation of word and total=1: INSERT INTO WORD_COUNT(TOTAL, WORD) SELECT 1,…
K. Weber
  • 2,643
  • 5
  • 45
  • 77
0
votes
1 answer

ON DUPLICATE KEY UPDATE in public function php not working

I am new to php and working on a pdo crud class. My insert function by itself works, but I am trying to have one function for both insert and update. I researched and saw that you can use ON DUPLICATE KEY UPDATE to do this, but when I add it to my…
meztli
  • 449
  • 2
  • 9
  • 20
0
votes
1 answer

Combining bulk Insert and Save in mongodb using Java? Is there a way through which we can achieve it?

I am pretty sure how INSERT works in mongodb, but I want insert to insert the data and in case the Id already exists I want to update the data like SAVE in mongodb. Example: If my entry in test collection is like, { "_id":ObjectId("68768242ge"),…
Harry
  • 3,072
  • 6
  • 43
  • 100
0
votes
1 answer

MySQL on duplicate - Insert but do not update

I have an SQL query that looks like this (WordPress options). INSERT INTO wp_options (option_name, option_value, autoload) VALUES ( 'category_children', 'a value', 'yes' ), ( 'test_options', 'testing', 'yes' ) ON DUPLICATE…
Jens Törnell
  • 171
  • 3
  • 9
0
votes
1 answer

Codeigniter with xpath and on duplicate key update

Looking for a bit of advice. I have an update script for my website’s database, but as yet - I’ve not been able to figure out how to convert it to the Codeigniter framework ie. it’s saved as it’s own file in the home directory of my website, and…
user2505513
  • 343
  • 4
  • 9
  • 24
0
votes
2 answers

when matched update not working oracle merge

Here is something interesting! The merge statement works fine. But when the values match, it does not update the status to 'B' as expected. Any idea why? merge into bbbt b using (select bank,ifsc,branch, center,district,state, …
SSG
  • 27
  • 2
  • 9
0
votes
1 answer

why doesn't PostgreSQL have ON DUPLICATE KEY?

Is this a perpetually denied feature request or something specific to Postgres? I've read that Postgre has potentially higher performance than InnoDB but also potentially larger chance of less serialization (I apologize that I don't have a source,…
user1382306
0
votes
2 answers

SQL: auto_increment of primary key counts different since I added unique keys?

Today I added two unique keys (external_id, name) to my table. Since then the counting of the id-column (primary key) is very weird and I'm not able to reproduce the issue. I didn't delete any row, but I updated (ON DUPLICATE KEY). I'd like the…
Mr. B.
  • 8,041
  • 14
  • 67
  • 117
0
votes
1 answer

Is this valid "on duplicate key" syntax?

I have no place to test this right now and I was hoping someone knows so I don't have to wait until tomorrow to find out.... insert into item_properties (ItemID, PropID, Value, UpdateOn) values (538, 25, 'some description stuff goes…
gloomy.penguin
  • 5,833
  • 6
  • 33
  • 59
0
votes
1 answer

How to insert or update all values in FIND_IN_SET and update the NOT FIND_IN_SET On Duplicate Key update

here is what im trying to do: Table called departments has many-to-many relation with table called employees. so, table department_employees has columns: department_id, employee_id, is_active. indexed department_id, employee_id as pk. I get a string…
Bergkamp
  • 599
  • 2
  • 6
  • 22
0
votes
1 answer

INSERT data from one table to another while ignoring duplicate keys

I have two MySQL tables. The first table has a cron job running where it gets updated every five minutes. When the cron job runs, it moves all the data from the first table into the second table (an archive table), truncates the first table and then…
MillerMedia
  • 3,651
  • 17
  • 71
  • 150
0
votes
0 answers

How write the ignore dupkey command in unix?

I know that in oracle the is a way to write to ignore the dupkey, something like /*+ ignore_row_on_dupkey_index(tab, index_tab) */ Is there a way to do the same thing but with unix commands? I think there's a way with WHENEVER SQLERROR EXIT…
Atlas91
  • 5,754
  • 17
  • 69
  • 141