Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminate records existing in table_1 & table_2

Status
Not open for further replies.

Christek

Technical User
Nov 27, 2002
4
DE
Hi,
i have 2 tables containing data in records. I want to eliminate records which are equal in field1 in both tables: table_1 and

table_2.

Example:


table_1: table_2:
field1 field2 field1 field2
record1 a a record1 a a
record2 b b record2 b x
record3 c c


The target is to have a third table containing the "non-equal" records - non equal means: not equal in field1.
So the target table should be:

table_3:
field1 field2
record1 c c (table_1, record3 is not in table_2)
(remark: record b,b/ b,x is equal in field1 an doesn't appear in the target table)


I hope I made sense...

Thanks!
 
insert into table_3
select * from table_1 t1
where not exists (select 'x' from table_2 t2
where t2.id = t1.id)

I think that sql should do it. --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top