homepage Welcome to WebmasterWorld Guest from 54.196.62.132
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Copy Certain Fields To A New Row In MySQL?
Planet13




msg:4432142
 3:53 pm on Mar 22, 2012 (gmt 0)

Hi there, Everyone:

I would like to copy certain fields to a NEW ROW in the same table in a MySQL database.

For example, the structure Might look like this:

ID (primary key) | SKU | TYPE | VALUE
0001 | ABC321 | phone_number | 555-1212

I would like to COPY the SKU field (ABC321) and the VALUE field (555-1212) but would like to have a NEW value for the TYPE field (change it from phone_number to custom_phone).

And of course, the ID (which is a primary key) should be populated automatically.

So in my example, I would like to take this data:

0001 | ABC321 | phone_number | 555-1212

And copy it into:

0002 | ABC321 | custom_phone | 555-1212


Also, how can I use ignore so that it doesn't create a duplicate row if one already exists?

Thanks in advance.

 

Dijkgraaf




msg:4432315
 10:38 pm on Mar 22, 2012 (gmt 0)

What you want is something like

INSERT INTO 'table' (list of columns to insert)
SELECT list of columns/values
FROM 'table'
WHERE condition of row to copy
AND NOT EXISTS ( SELECT to check to see if row already exists )

Planet13




msg:4434184
 11:10 pm on Mar 27, 2012 (gmt 0)

Thanks so much, Dijkgraaf

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved