473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Compare two tables field by field

4
Hi,
i need to compare two tables, field-by-field. The matching will be based on a key field, and the comparison will be for the non-key fields. If there is a mismatch, the key fields, along with the mismatch value (like-> Key, table1.field, table2.field)

can this be done using SQL? Or do we need to write any programs for this?

GP
Dec 26 '13 #1
7 1876
Rabbit
12,516 Expert Mod 8TB
Yes, join on your key and in the WHERE clause, return only the non matches.
Dec 26 '13 #2
PNair
4
I tried that, but if i do that, i will not know which row or which field has the mismatch, unless i got line by line. Let me try to explain with the example below:

Table1 Fld 1 Fld 2 Fld 3
Key 1 A B C
Key 2 A B C
Key 3 A B C

Table2 Fld 1 Fld 2 Fld 3
Key 1 A X C
Key 2 A B Y
Key 3 A B Z

The output I am looking for is something like this:

Key1, Field2, B, X
Key2, Field3, C, Y
Key3, Field3, C, Z

If I just get a list of key fields, then I need to review them row by row to find out which column has a mismatch.
Dec 26 '13 #3
Rabbit
12,516 Expert Mod 8TB
In that case, use a union for each field that you need data returned on.
Dec 27 '13 #4
PNair
4
Thanks for the quick response. I will research on UNION and figure out how to use it. Meanwhile, if you have a sample query, could you pls share? Or makeup a simple SQL with one field. that would help.

Thanks again,
Dec 27 '13 #5
zmbd
5,501 Expert Mod 4TB
PNair, we usually as that you show your work first. You'd be surprised at how many students like to troll. (^.^)
Dec 27 '13 #6
PNair
4
Here is my query. I had to make some edits to remove the table name and field name, but the structure is same.

As you can see, I am doing a SELECT *, which will give me all rows which has a mismatch. I cannot know which of the 3 conditions failed.


Expand|Select|Wrap|Line Numbers
  1. SELECT * 
  2. FROM   TABLE1 PD 
  3.        INNER JOIN TABLE2 PM 
  4.                ON PM.KEY = PD.KEY 
  5. WHERE  PM.FIELD1 <> PD.FIELD1 
  6.     OR PM.FIELD2 <> PD.FIELD2 
  7.     OR PM.FIELD3 <> PD.FIELD3
Dec 27 '13 #7
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

Split it up into multiple queries and use a UNION to join the results.
Dec 27 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tdmailbox | last post by:
I need to migrate data from one sql database to another. The second DB is a newer version of the "old" database with mostly the same tables and fieldnames. In order support some reporting queries...
1
by: Prakash RudraRaju | last post by:
Hi, I have recently migrated MSAccess Tables (nearly 120) to MySQL. To test successful migration I want to compare all tables. I have linked MySQL tables through ODBC connection. I want to...
4
by: dfs9 | last post by:
In the article "Delete Duplicate Records From Access Tables" By Danny Lesandrini writes the following: This final suggestion is the most flexible and accurate. Given any table, it generates a...
6
by: Bob Alston | last post by:
I have an Access software app installed in 8 locations. Updates are becomming very time consuming. Updating everything but the tables in the backend is quite easy. The difficult part is...
2
by: sparks | last post by:
I am trying to find valid records in a table but I must compare a date field to a date stored in the table I can see where this is wrong (ok I guess its not text) "= """ & Me.date & """" so...
5
by: Edd E | last post by:
Hi, I have a database to store my analyses (Access 2002, WinXp), the basic structure is: TABLE 1 = Sample Info TABLE 2 = Analysis type 1 TABLE 3 = Analysis type 2 TABLE 4 = Analysis type 3 ...
6
by: PierpaoloScappatura | last post by:
Dear All, I need to compare two tables with same fields. Table1(A,B,C) Table2(A,B,C) Select * From Table1,Table2 Where Table1.A=Table2.A AND Table1.B=Table2.B AND Table1.C=Table2.C Query don't...
4
by: BarryB | last post by:
I imported a large table of classes, teachers and students from Excel to MS Access. Up to a point, this worked out ok. Unfortunately, the students are represented as field names (Smith_Abigail,...
7
by: Deano | last post by:
Got a bit of a major task coming up - I need to migrate data from one version of my mdb to another. Normally I manually track what's changed but there have been so many alterations it's been...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.