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
 General SQL Server Forums
 New to SQL Server Programming
 Comparison of 2 tables

Author  Topic 

Mmm
Starting Member

2 Posts

Posted - 2013-07-13 : 06:05:32
Hi,

need some help :) I am fairly new to this so please bear with me.

I am doing this 2 queries, they get data from the same tables in a very different way. The new way is a lot faster but of course there are problems. There are some discrepancies in the results. Both queries produce results with more than 200.000 rows. Second one has ca. 100 rows less than the first one and some of the results are wrong (most are correct though).

My question is how do I find the differences. I did the left outer join when column a.result != b.result (lines are defined by date and ID so they should be unique).

but the join gives me problematic results (some are not different at all, some differences are not in the result).

so how do I find the differences between 2 queries, including missing results/rows?

Thanks in advance for help :)

Mmm

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-07-13 : 06:30:06
SELECT * FROM dbo.Table1 AS t1 WHERE NOT EXISTS (SELECT * FROM dbo.Table2 AS t2 WHERE t2.Date = t1.Date AND t2.ID = t1.ID)

Also see http://weblogs.sqlteam.com/peterl/archive/2007/09/20/Finding-records-in-one-table-not-present-in-another-table.aspx



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-07-13 : 06:31:20
And this http://weblogs.sqlteam.com/peterl/archive/2009/06/12/Timings-of-different-techniques-for-finding-missing-records.aspx



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Mmm
Starting Member

2 Posts

Posted - 2013-07-13 : 08:03:41
Thank you for the swift reply :)

Go to Top of Page
   

- Advertisement -