Jump to content

mysql query


nikhilthecool

Recommended Posts

purpose-want to make a duplicate of a record in the same table with few of the column values changed
PS-there are more than 100 columns so treating them individually would be quite cumbersome
qry-> insert into table1 select * from table1 where xyz='abc'

when i execute this qry i get a copy of the record whose xyz='abc' but there are certain columns which i need to change then itself
and what if there are certain unique fields?? what do i do then?



Link to comment
Share on other sites

Well, with ~100 columns (!?!? -- this can't be good), INSERT INTO... SELECT WHERE seems out of the question -- you're not going to maintain such a huge column list. You could always just copy it and keep track of the LAST_INSERT_ID(), and update whatever needs updating, presumably <100 columns. Of course, as you alluded to, unique keys are going to be a problem. You might as well copy this to a dummy / temporary table, change the values, and then copy it back.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.