View Full Version : Copying a row, but changing a value
blinks
08-17-2009, 10:38 AM
I need to insert a whole row from one table to another, but changing just one value before doing the insert. I could do it column by column, but this seems a bit time-consuming? Any suggestions??
TIA
DaiLaughing
08-17-2009, 12:17 PM
SELECT, change value and then INSERT seems easy enough to me.
blinks
08-17-2009, 12:47 PM
What syntax would I use exactly.
Fumigator
08-17-2009, 07:20 PM
There are many "how-to" tutorials on the web, which you can find using Google. Try search terms like "mysql +php +select +tutorial".
Old Pedant
08-17-2009, 09:29 PM
INSERT INTO newtable ( fieldA, fieldB, fieldC, fieldD )
SELECT fieldX, fieldY, 3.14159265 * zamboni + 2.718281828, fieldZ
FROM oldtable WHERE someField = someValue
A silly example, modifying the "zamboni" value before inserting it into fieldC of the new table, but you hopefully get the idea.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.