[PHP] probably a simple mysql copy multiple rows question
Hi All, I have a table with a structure like this. name code price what i would like to do is copy the data in these rows to new ones in the same table but change the name col, keep the current data for code col and set price col to a default value. so if the output of my current table is BASE 600 1.99 BASE 601 2.99 then i would like to copy these rows so that the table looks like this BASE 600 1.99 BASE 601 2.99 NEW600 33 NEW601 33 i hope that makes some kind of sence... Dave C -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] probably a simple mysql copy multiple rows question
Dave Carrera wrote: so if the output of my current table is BASE 600 1.99 BASE 601 2.99 then i would like to copy these rows so that the table looks like this BASE 600 1.99 BASE 601 2.99 NEW600 33 NEW601 33 This is a SQL question, not PHP. That said, what you're describing is INSERT...SELECT syntax. In your example, something like: INSERT INTO mytable (name, code, price) SELECT 'NEW', code, '33' FROM mytable WHERE name = 'BASE' /* or whatever rows you need to copy */ Supported by MySQL, PostGres and others. -- Max Schwanekamp http://www.neptunewebworks.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php