Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT ... ON DUPLICATE KEY UPDATE with a SELECT ... statement

Status
Not open for further replies.

UltraSmooth

Programmer
Oct 28, 2002
97
CA
I have a temporary table that contains records I need to update against a live table. I'm trying to use the INSERT ... ON DUPLICATE KEY UPDATE statement to update all records in the live table with those in the temporary as well as insert any new records from the temporary table.

The problem is I can't seem to get this to work using a SELECT statement, something like this:

INSERT INTO tblA (id,name,...)
SELECT (id,name,...) FROM tmp_tbl
ON DUPLICATE KEY UPDATE;

In the documentation it doesn't say if you can or can't use a SELECT statement along with a ON DUPLICATE KEY UPDATE statement but it does not show an example of this in the syntax templates.

Is this possible to do and if so what is the correct syntax?

My workaround solution is to use the INSERT REPLACE statement to just replace all duplicate records but I'm assuming this is a slower process since it would have to create the primary key indexes? I'm trying to do this update procedure as fast as possible, speed is very important in my situation since I have to update 25 tables in this fashion every night.

Thanks for any help.
 
Yes, sorry my mistake but that is what I meant...REPLACE INTO statement
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top