Solved

compare data

Posted on 2011-02-12
4
386 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

777 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