I need to create a delta table that shows me the differences between two tables (I need to know which rows have been added, which rows have been deleted, and which rows have changed from the old table to the new table). The old and new table have 5 fields with the exact same information. I do not have a primary key in my access database that links the two tables because many of the rows have duplicates in 2 or more fields.
Mind you, I am very new to access and this example below may not be the best example or the best way for what I want to be represented.
Example:
Table1 ("Old")
Field1, Field2, Field3
XX, VV, H
XX, VV, P
YY, GG, N
ZZ, GG, N
Table2 ("New")
Field1, Field2, Field3
XX, VV, S
XX, VV, P
YY, GG, N
HH, FF, C
What I want the query to show
Field1, Field2, Field3, Changes
S Field3 Updated
GB F Field Updated
Row 3 Removed
Row 4 Added
This is what I have done so far. - SELECT Old.*, New.*,
-
"Field Updated" As Comment
-
FROM Old
-
inner JOIN New
-
ON Old.Field1 = New.Field1 AND Old.Field2= New.field2 and Old.field3=New.field4
-
union
-
-
SELECT Old.*, New.*,
-
"No Change" As Comment
-
FROM Old INNER JOIN New ON (Old.Field1 = New.field1) AND (Old.field2 = New.field2) AND (Old.field3 = New.field3) AND (Old.field4= New.field4) AND (Old.field5 = New.field5);
-
-
-
Union
-
-
SELECT Old.*, New.*,
-
"Deleted" as Comment
-
FROM Old LEFT JOIN New ON (Old.field1 = New.field1) AND (Old.field2 = New.field2) AND (Old.field3 = New.field3) AND (Old.[field4] = New.[Field4])
-
WHERE (((New.Field1) Is Null) AND ((New.Field2) Is Null) AND ((New.Field3) Is Null) AND ((New.field4) Is Null));
-
-
UNION
-
SELECT Old.*, New.*, "Added" as Comment
-
-
FROM New LEFT JOIN Old ON (New.field1 = Old.field1) AND (New.field2 = Old.field2) AND (New.field3 = Old.field3) AND (New.field4 = Old.field4) AND (New.[field5] = Old.[field5])
-
WHERE (((Old.field1) Is Null) AND ((Old.field2) Is Null) AND ((Old.field3) Is Null) AND ((Old.field4) Is Null) AND ((Old.field5) Is Null));
Please I am in desperate need of any advice and suggestions. Please be as specific as possible with your answers since I am knew to this!! Thanks
1 1784 NeoPa 32,556
Recognized Expert Moderator MVP
I see this question as borderline acceptable. It is almost a simple request for the work to be done, but there is some work already done, albeit very confused looking and a long way short of practical. Nevertheless, effort has been shown and work has been done already so I'm inclined to go ahead. My approach will be to attempt to lead towards a solution rather than simply to provide one.
To this end I would ask you first to consider (and then explain to us) what should actually be used to identify records from the two tables as matches. What you suggest (That all five fields contain the same values) is inconsistent with the idea of showing where the same records exist but have been changed (As that would make no sense in the scenario described).
When we have a clear idea of exactly what we're looking for I will ask you to do your best to produce each of the queries that go together to make up the whole solution. That way we will be breaking down the problem into manageable chunks. It will also force you to focus your understanding on each of the situations separately, before we bring them all together. A task that will make better sense to you once you've been through each individually.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paolo Alexis Falcone |
last post by:
Whenever I try to access a table with many rows using PgSQL's
fetchall(), this happens:
>>> from pyPgSQL import PgSQL
>>> db = PgSQL.connect("192.168.0.8:5432:whitegold","dondon","dondon")
>>>...
|
by: Support |
last post by:
Hi,
I want to know if I have changed a few records in my database using update /
insert / delete methods, how can i later know which rows have been changed
or modified ?
I know the...
|
by: anthonyroach |
last post by:
I can create a dumpfile to see the rows rejected by the load. How can
I see the rows deleted in the delete phase?
|
by: Plissken.s |
last post by:
Hi,
how can i compare a string which is non null and empty?
i look thru the string methods here, but cant find one which does it?
...
|
by: rochelle28 |
last post by:
i want to compare the two consecutive rows in the table such that if
the first row contains handset in the category column and the next row contins simcard in category column it will alert the user,...
|
by: jb1 |
last post by:
Hello All,
I am trying to create a DTS package.
I have two tables tbl_A and tbl_B with similar data/rows but no
primary keys.
tbl_A is master.
I would like this package to query tbl_A and...
|
by: Sam Durai |
last post by:
Whenever delete is performed on a DB2 database, it just returns
"...command completed successfully.."
db2 =select count(*) from sales
1
-----------
12
1 record(s) selected.
db2 =delete from...
|
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: site |
last post by:
Have to compare dates of two rows in one table
Input table
COL1| COL2| COL3| COL4
1| A| 1-Jan-07| 6-Feb-08
2| A| 7-Feb-08| 31-Mar-08
3| A| 1-Jan-09| NULL
SQL code to compare COL 4 date (Row...
|
by: evildracko |
last post by:
first a write error prompt
Title: Write Conflict
Text: This record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |