Jump to content


mysql query

  • Please log in to reply
1 reply to this topic

#1 nikhilthecool

  • Members
  • PipPip
  • Member
  • 18 posts

Posted 09 May 2006 - 08:42 AM

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?

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 May 2006 - 03:40 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users