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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two tables

Status
Not open for further replies.

Kingkumar

Programmer
Jan 21, 2003
167
US
Hi i have exactly same two datables in two seperate databases and i want to compare the two tables and get teh rows which are not in second table
I tried to use

select * from t1, t2
where t1.c1 <>t2.c1 and t1.c2 <>t2.c2

but this query is returning too many rows atleast 4 times the number of original rows

then i tried
select * from t1 minus select * from t2 it returned wrong results
Can anyone help in this one.
Thanks for ur help in advance
regards,
king
 
[/code]
select * from t1
where c1 not in (select c1 from t2)
and c2 not in (select c2 from t2)
[/code]

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
OR
Code:
select * from t1
where c1 not in (select c1 from t2)
and c2 not in (select c2 from t2)

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Hi,

I am not sure if you are using MS SQL or Oracle but
MS SQL has ni MINUS set operator.

Another reason you might have incorrect results is
because you might have nulls in either C1 or C2
so you can use the isnull function to replace nulls with
spaces and this should give you the desired result using
the query provided in the previous response

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top