Solarpitch Posted July 17, 2008 Share Posted July 17, 2008 Hi, Is there anyway to run a script that will copy the contents of one column into another. For example, say I wanted to copy the contents of image to Image_2 could I do this? from this... ID Name Image Image_2 1 Dave dave.gif 1 Patrick patrick.gif 1 Ian ian.gif to this... ID Name Image Image_2 1 Dave dave.gif dave.gif 1 Patrick patrick.gif patrick.gif 1 Ian ian.gif ian.gif Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/ Share on other sites More sharing options...
Firestorm3d Posted July 17, 2008 Share Posted July 17, 2008 you can try something like this UPDATE database.table t1, database.table t2 SET t2.image_2=t1.image I think that might do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592395 Share on other sites More sharing options...
Solarpitch Posted July 17, 2008 Author Share Posted July 17, 2008 Thanks but when I tried this.. UPDATE products product_image, products product_image_2 SET product_image_2 = product_image I got.. #1052 - Column 'product_image_2' in field list is ambiguous Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592426 Share on other sites More sharing options...
PFMaBiSmAd Posted July 17, 2008 Share Posted July 17, 2008 You are doing this in a single table. Reading the mysql UPDATE section in the manual would probably help - Single-table syntax: UPDATE [LOW_PRIORITY] [iGNORE] tbl_name SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_condition] [ORDER BY ...] [liMIT row_count] The bold parts are what you need. Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592482 Share on other sites More sharing options...
Firestorm3d Posted July 17, 2008 Share Posted July 17, 2008 you need to put in t1 and t2. its part of the mysql code. it takes 2 snapshots in other words of the tables and then traverses the entire table. UPDATE products t1, products t2 SET t2.product_image_2 = t1.product_image Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592845 Share on other sites More sharing options...
fenway Posted July 17, 2008 Share Posted July 17, 2008 you need to put in t1 and t2. its part of the mysql code. it takes 2 snapshots in other words of the tables and then traverses the entire table. UPDATE products t1, products t2 SET t2.product_image_2 = t1.product_image Strictly speaking, you need the join condition -- it's an accident if it works. Quote Link to comment https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.