Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to display differences

Status
Not open for further replies.

kersten

Programmer
Apr 6, 2001
1
CA
I have 2 tables that contain the same columns (12 columns), one contains current records and the other contains previous records.
What I want to do is find any differences in the rest of the columns, based on t1.col1 = t2.col1 and t1.col2 = t2.col2 and t1.col3 = t2.col3, but the rest of the column values may be different.

Thanks in advance
 
select ... from t1 inner join t2 on
t1.col1 = t2.col1 and t1.col2 = t2.col2 and t1.col3 = t2.col3
where
t1.x<> t2.x John Fill
ivfmd@mail.md
 
Hiya,

The easiest way to do this is:

SELECT t1.col1,
t1.col2,
t1.col3,
any other columns that you want to see
FROM table1 t1,
table2 t2
WHERE t1.col1 = t2.col1
AND t1.col2 = t2.col2
AND t1.col3 = t3.col3
AND (t1.col4 != t2.col4 OR
t1.col5 != t2.col5 OR
t1.col6 != t2.col6 OR
.
.
t1.col12 != t2.col12)

This will provide a list of any rows where there is any difference between the tables.
However, this could get quite complicated when you are trying to view the output, so it may be better to write a number of queries and just focus of one column per time.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top