comparing two tables

  • Thread starter Thread starter MORALBAROMETER
  • Start date Start date
M

MORALBAROMETER

Hi all,
I have two tables that are not link. But their content are
interrelated. I want to find out what is in one table that is not in
the other and vice-versa. how can archieve this in c# or within the
database.
thanks
 
If the tables are in SQL then probably let the database do the hard work.

I assume that there is some common key between the two tables (identifier).
If you had two tables called T1 and T2 and ID was the common key then:

SELECT * FROM T1 WHERE T1.ID NOT IN (SELECT ID FROM T2)

Would return all of the records in T1 that are not in T2. Just swap the
table names above to invert this.

Would probably make sense to ensure that there was an index on the ID column
in each table to speed up the join.

HTH

- Andy
 
It is not a C# issue,You can do it using a simple sql query,

Something like it:

Select * From T1 Where ID Not In (Select ID From T2)
 
Thanks alot. The tables have not common key. their keys are dereived
from same table.
 
Thanks alot. The tables have not common key. their keys are dereived
from same table.
 
Not sure I follow you; so what fields do the two tables have in common (or
how can they be linked via another table if necessary)?

- Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top