sikyala
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
if so..., try something like this pdate table1 set field1 = (select field2 from table2 where table1.id = table2.id)
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)
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
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
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...
ASKER
not sure what happened. but both fields are in 1 table
ASKER
thanks
- no problem aikyala. glad i'm able to help
UPDATE tablename SET field1 = field2