Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

compare data

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
VBdotnet2005
Asked:
VBdotnet2005
  • 2
2 Solutions
 
wdosanjosCommented:
Something like:

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

0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
 
Anthony PerkinsCommented:
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
 
wdosanjosCommented:
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now