Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Exact Match of Two tables

Author  Topic 

kamalkishore_in
Yak Posting Veteran

76 Posts

Posted - 2002-03-27 : 01:14:31
Hi

I have two tables Say TableA and TableB.
Structure of the both the tables are same.
Table Name : TableA
Fields are:
Code int
Amount Int

Data for TableA is
Code, Amount
1,100
2,200
4,400



Data for TableB is
Code, Amount
1,100
2,300
3,0
4,400

My question is : I wants to match of Code and amount of both tables
Tables should exactly match of Data to each other.

Looking for the query..
Need help.








Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-27 : 01:17:56
You just add an extra condition to your join clause.

I.e.


SELECT *

FROM

TableA

INNER JOIN TableB ON TableB.Code = TableA.code AND
TableB.Amount = TableA.Amount



Hope that helps

Damian
Go to Top of Page

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-03-27 : 08:54:47
sql server can also compute checksums for rows and tables. for very large rowsets that might be advantageous - plus you don't have to write specific queries for each table pair comparison.

setBasedIsTheTruepath
<O>
Go to Top of Page

kamalkishore_in
Yak Posting Veteran

76 Posts

Posted - 2002-03-27 : 20:30:16
Hi Dear,
I think my question was not very clear.
I need to know How many records are not matching. (Count)
Waiting...

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-03-27 : 20:41:56
Your question was very clear. You just asked the WRONG question. You didn't mention ANYTHING about counting the number that didn't match.



SELECT count(*)

FROM

TableA

LEFT JOIN TableB ON TableB.Code = TableA.code AND
TableB.Amount = TableA.Amount

WHERE TableB.Code is NULL



quote:

Waiting...


That is verging on rude considering YOU made the mistake. Think about it a little more next time.


Damian

Edited by - merkin on 03/27/2002 20:42:25
Go to Top of Page
   

- Advertisement -