How to merge two database tables when only some fields are common?
In MS Access I have two tables (A and B), and the task is to insert B into
A. However, there are some special conditions:
All fields are of type text.
A and B have a some common fields.
The same key field is guaranteed to exist in both, and its values to be
always different.
A has some fields that B does not have. The inserted records should have
those fields blank.
B has some fields that A does not have. These fields must be created in A,
and the existing records in A should have them blank.
There are many cases like this one, so the query should not explicitly
include the field names, since it would be tedious to personalize the
query for each case. However, the key field is always named the same.
Creating a new table C instead of directly replacing A is acceptable.
Example:
Table A:
key field_a field_b field_c
--- ------- ------- -------
k0 hello dear world
k1 bye cruel world
Table B:
key field_a field_d field_e
--- ------- ------- -------
k2 welcome john doe
k3 turulu ann harp
Table C (the new A):
key field_a field_b field_c field_d field_e
--- ------- ------- ------- ------- -------
k0 hello dear world
k1 bye cruel world
k2 welcome john doe
k3 turulu ann harp
No comments:
Post a Comment