Jump to content

Copying a column?


Solarpitch

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/115209-copying-a-column/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592482
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/115209-copying-a-column/#findComment-592860
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.