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
https://forums.phpfreaks.com/topic/9370-mysql-query/
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
https://forums.phpfreaks.com/topic/9370-mysql-query/#findComment-34939
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.