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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Compare all fields

Status
Not open for further replies.

TidyTrax

Programmer
Joined
Jul 11, 2001
Messages
263
Location
AU
Hi,

I have two identical databases - that i want to merge into one - what i need is a sql query that will look at all fields in a table and compare them against the same field in the other database and tell me the fields that have diffences - so it would be like - where table1.field1 <> table2.field1 or table1.field2 <> table2.field2

But in a quicker more slick fashion
 
can you not just left join on all fields in the 2 tables, and then select the ones with missing joins...

but you would have to left join the other way to get missing records on both sides, plus if you're typing all this out then it's not actually any easier than the where statements...

another option is to import both the tables into another seperate table, and then do a count(), if any have less than 2, then you've got one record missing...

--------------------
Procrastinate Now!
 
got an F1 button on your keyboard? There's plenty of examples in the help.

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
SELECT DISTINCT table1.field1
FROM table1 LEFT OUTER JOIN
table2 ON table1.field1 = table2.field1
WHERE table2.field1 IS NULL

This should give you everything from table1 that did not have a match in table2.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top