Linked Questions

1185 votes
13 answers
1.4m views

I want to add a row to a database table, but if a row exists with the same unique key I want to update the row. For example: INSERT INTO table_name (ID, NAME, AGE) VALUES(1, "A", 19); Let’s ...
Keshan's user avatar
  • 14.7k
40 votes
4 answers
40k views

Kinda strange to put it into words that short, heh. Anyway, what I want is basically to update an entry in a table if it does exist, otherwise to create a new one filling it with the same data. I ...
unrelativity's user avatar
  • 3,710
28 votes
3 answers
28k views

i am running a query in mysql insert ignore into........ using Python after running the query I want to know the primary key of the row. I know there is the query SELECT LAST_INSERT_ID(); but i'm ...
John's user avatar
  • 22.1k
16 votes
3 answers
12k views

I want to write a program add new item to table. This item has an unique key name and it can be created by one of 100 threads, so I need to make sure that it is inserted only once. I have two ideas: ...
user3245050's user avatar
15 votes
2 answers
11k views

I have a "tags" table, which has a UNIQUE on the "tags" column, to prevent duplicates. I have a "bookmarks_tags" table, which relates bookmarks to tags, and it has a UNIQUE on the "bookmark_id" and "...
Wayne Smallman's user avatar
9 votes
5 answers
14k views

This is my query: INSERT INTO table (value) VALUES (value) ON DUPLICATE KEY UPDATE value=value With mysql_insert_id() I get the new inserted ID, but how to get the ID of row updated? I tried ...
Leonardo's user avatar
  • 2,383
3 votes
2 answers
9k views

im trying to create a function CREATE FUNCTION `func`(param1 INT, param2 INT, param3 TEXT) RETURNS int(11) BEGIN INSERT INTO `table1` (`column1`, `column2`, `column3` ) VALUES (param1, param2, ...
ianace's user avatar
  • 1,635
2 votes
2 answers
4k views

I have a query like so: INSERT INTO table1 (field1,field2) VALUES ('$value1','$value2') ON DUPLICATE KEY UPDATE field1 = '$value1' I then want to get the last insert id if it does the insert, how can ...
John's user avatar
  • 10.2k
1 vote
1 answer
4k views

I'm using sqlalchemy to do an INSERT ... ON DUPLICATE KEY UPDATE in MySQL, and I'm trying to find the lastrowid of the primary key that was inserted or updated. However, when the DUPLICATE clause is ...
user3450049's user avatar
4 votes
2 answers
2k views

I am looking for a statement that will try to insert a row into a table, but return the primary key of the duplicate row if one is encountered. One field in the table is the auto incrementing primary ...
VWD's user avatar
  • 135
0 votes
1 answer
1k views

I'm stumped on this one. I'm a little above beginner-level with PHP/MySQL and very new with posting on this site. GoDaddy switched me over to a grid server to boost performance and shed light on a ...
lindenmj's user avatar
0 votes
1 answer
979 views

OK the question is NOT about how to return the ID, but more like how to skip it... I have a situation where i use last_insert_id() to get the id of the last inserted row, but i want to get a zero if ...
Marius's user avatar
  • 4,006
0 votes
1 answer
643 views

email_address ------------- id prefix fqdn Prefix and fqdn together form a unique key. I would like to write a query which would do an insert, if the email address is not yet in the table. If the ...
fadedbee's user avatar
  • 45.2k
0 votes
1 answer
426 views

Pasted below is my MySQL Stored Procedure. CREATE PROCEDURE `newrig`( IN x varchar(10), IN y varchar (10), IN z varchar(5), OUT a INT ) BEGIN INSERT INTO rig (Name, Model,Type) ...
roger's user avatar
  • 35
0 votes
2 answers
292 views

I have a following map table, with a unique key on the name column: id | name 1 aaa 2 bbb 3 ccc I want to get a newly created ID if I insert a new value to this table, like this: INSERT ...
user99999's user avatar
  • 2,044

15 30 50 per page