Link to home
Start Free TrialLog in
Avatar of sikyala
sikyalaFlag for United States of America

asked on

how do I copy contents from one field to another field

I am trying to copy the contents of one field to another field in a table. is it as simple as setting one field equal to another. The field i am copying has several different values and I want the right value for each record to be copied to that record. so for example if the record is

id       field 1      
1        AVON
2        comcast
3       verizon

then in field 2 I would want the same

id       field 2
1        AVON
2        comcast
3        verizon


my concern is would it set all fields to AVON
Avatar of OP_Zaharin
OP_Zaharin
Flag of Malaysia image

- try this:
UPDATE tablename SET field1 = field2
ASKER CERTIFIED SOLUTION
Avatar of OP_Zaharin
OP_Zaharin
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean Stuber
Sean Stuber

are these fields in different tables?

if so..., try something like this pdate table1  set field1 = (select field2 from table2 where table1.id = table2.id)
Avatar of sikyala

ASKER

they are in the same table
- if its in the same table, my suggestion in ID: 36931461 would update the field2 to be the same as field1.
you mean this I guess

UPDATE   table2
   SET   field2 =
            (SELECT   field1
               FROM   table1
              WHERE   table1.id = table2.id)
HainKurt

that was already posted above
but no, it's an update to the same table
sdstuber, I know it is posted before by you (36931520), just I corrected the sql you posted since he wants to update Table2 not Table1 (if they are in seperate tables)...
HainKurt,

sorry, I didn't know you were addressing that to me.  Unless somebody is called out, I assume all posts are addressed to the asker.


but...there really wasn't anything to correct,  the table wasn't specified  so it was just 2 tables that I named 1 and 2
since the table and column names were need to be changed to the real names anyway,  1/2  vs 2/1  vs x/y, etc isn't more or less correct

maybe I should have named them sourcetable and targettable  - sorry for any confusion
yes, I should address you :) my mistake...
Avatar of sikyala

ASKER

not sure what happened. but both fields are in 1 table
Avatar of sikyala

ASKER

thanks
- no problem aikyala. glad i'm able to help