Solved

compare data

Posted on 2011-02-12
4
383 Views
Last Modified: 2012-05-11
How to compare data between two table? I want to compare if account and date on two table if are the same<br />Table1<br />ID account order date <br />Table2<br />ID account order date<br />
0
Comment
Question by:VBdotnet2005
  • 2
4 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34879523
Something like:

Select t1.accountid, t1.orderdate, t2.orderdate from t1, t2 where t1.accountid = t2.accountid and t1.orderdate <> t2.orderdate

0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 34879540
use third party tools like red-gate data compare and apex data compare
http://www.red-gate.com/products/sql-development/sql-data-compare/
otherwise
compare the count *
then
select count(*) from ( select * from table1 union select * from table2 ) a  -- if it is the same then the tables are same

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 34879620
Something like this perhaps:
SELECT *
FROM	Table1 t1
	FULL OUTER JOIN Table2 t2 ON t1.ID = t2.ID
WHERE	t1.Account <> t2.Account 
	OR t1.OrderDate <> t2.OrderDate
	OR t1.ID IS NULL
	OR t2.ID IS NULL

Open in new window

0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 250 total points
ID: 34880184
Sorry I misread your question. Here is the correct script.  The first one lists the records with different order dates.

Select t1.accountid, t1.orderdate, t2.orderdate from t1, t2 where t1.accountid = t2.accountid and t1.orderdate = t2.orderdate

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now