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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.