Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how do I copy contents from one field to another field

Posted on 2011-10-07
13
Medium Priority
?
276 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:sikyala
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36931456
- try this:
UPDATE tablename SET field1 = field2
0
 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 2000 total points
ID: 36931461
ops sorry. its the other way around:

UPDATE tablename SET field2 = field1
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36931520
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)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:sikyala
ID: 36931533
they are in the same table
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36931542
- if its in the same table, my suggestion in ID: 36931461 would update the field2 to be the same as field1.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 36931549
you mean this I guess

UPDATE   table2
   SET   field2 =
            (SELECT   field1
               FROM   table1
              WHERE   table1.id = table2.id)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36931559
HainKurt

that was already posted above
but no, it's an update to the same table
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 36931579
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)...
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36931603
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
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 36931676
yes, I should address you :) my mistake...
0
 

Author Comment

by:sikyala
ID: 36931787
not sure what happened. but both fields are in 1 table
0
 

Author Closing Comment

by:sikyala
ID: 36931791
thanks
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36931810
- no problem aikyala. glad i'm able to help
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question