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
7 1876
Yes, join on your key and in the WHERE clause, return only the non matches.
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.
In that case, use a union for each field that you need data returned on.
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,
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. (^.^)
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. - SELECT *
-
FROM TABLE1 PD
-
INNER JOIN TABLE2 PM
-
ON PM.KEY = PD.KEY
-
WHERE PM.FIELD1 <> PD.FIELD1
-
OR PM.FIELD2 <> PD.FIELD2
-
OR PM.FIELD3 <> PD.FIELD3
Please use code tags when posting code or formatted data.
Split it up into multiple queries and use a UNION to join the results.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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,...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
|
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...
| |