Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 04:02 - Jul 05, 2010  

MURIUKI4

HOW TO UPDATE DATA FROM TWO TABLES

THIS IS IN ORACLE DB I HAVE TABLE WITH CORRECT DATA AND THE OTHER WRONG DATA I WANT TO UPDATE FROM TABLE A TO B

Categories

Answer Discussion
Tutorials

 

Suleman

Date:: Jul 16, 2010

Time:: 10:02

Hi MuriUK,

Use this to get the correct data fill in from table A to table B.

this takes care of the exsisting but incorrect records by updating those rows with values from table A and the non-exsisting records in table B by inserting those rows from table A.



MERGE INTO B
USING A
ON (B.id = A.id)
WHEN MATCHED THEN
UPDATE
SET B_col1 = A_col1,
B_col2 = A_col2,
B_col3 = A_col3,
B_col4 = A_col4
WHEN NOT MATCHED THEN
INSERT (B_col1,B_col2,B_col3,B_col4)
VALUES (A_col1,A_col2,A_col3,A_col4);

Hope this helps.

anjith_ts

Date:: Mar 10, 2011

Time:: 01:27

A,
If you are sure that ,the two tables must contain same data ,then you can truncate the wrong data table and insert the data to it from the correct table by
Tuncate table <wrong_table>
insert into table <wrong_table> select * from <correct_table>;

B,
If you simply want to insert the data,which is not in wrong table
you can use the sql provided by Suleman

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es