Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Compare two tables and delete the common rows from table 1.

MrSaoJul 23 2012 — edited Jul 24 2012
Hi ,

I want to compare two tables ,
and delete the common rows from
the first table

Here is what i have done :

Create table test1(Test1C1 Number,
Test1C2 varchar2(50));


Create table test2(Test2C1 Number,
Test2C2 varchar2(50));


Insert into test1 values(1,'testdata1');
Insert into test1 values(2,'testdata2');
Insert into test1 values(3,'testdata3');
Insert into test1 values(4,'testdata4');
Insert into test1 values(5,'testdata5');
Insert into test1 values(6,'testdata6');
Insert into test1 values(7,'testdata7');
Insert into test1 values(8,'testdata8');
Insert into test1 values(9,'testdata9');
Insert into test1 values(10,'testdata10');

commit;

Insert into test2 values(1,'testdata1');
Insert into test2 values(3,'testdata3');
Insert into test2 values(5,'testdata5');
Insert into test2 values(7,'testdata7');
Insert into test2 values(9,'testdata9');

commit;

delete from test1 t1 where exists(
select * from test1
INTERSECT
select * from test2);

it deletes all the records from Table test1.

What should I modify here ? or should I write a differnet query ?

The desired contents in table test1 will be

2 testdata2
4 testdata4
6 testdata6
8 testdata8
10 testdata10
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2012
Added on Jul 23 2012
5 comments
1,801 views