Link to home
Create AccountLog in
Avatar of RSayadi
RSayadi

asked on

Matching columns from two tables

Hi,

I need to do the following in MS Access:

Match TABLE_A.[COLUMN_A] with TABLE_B.[COLUMN_A]

Every time there is a match, the value of of TABLE_B.[COLUMN_B] needs to be imported into TABLE_A.[COLUMN_B]

It's important that the value required is set into the first table and not just in a different query.

Can someone help out. Thank you in advance.
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of RSayadi
RSayadi

ASKER

Can you be more specific with the syntax. This generates syntax error on update.
Try this, using a FROM clause:

UPDATE TABLE_A 
SET TABLE_A.[COLUMN_B] = TABLE_B.[COLUMN_B]
FROM TABLE_A INNER JOIN TABLE_B
ON TABLE_A.[COLUMN_A] =TABLE_B.[COLUMN_A]

Open in new window


Alternatively, using a WHERE clause:

UPDATE TABLE_A, TABLE_B
SET TABLE_A.[COLUMN_B] = TABLE_B.[COLUMN_B]
WHERE TABLE_A.[COLUMN_A] =TABLE_B.[COLUMN_A]

Open in new window

If the names are all correct then the sql in my post should work.

If you have changed names then you will have to post your actual code for use to see what the problem is.
Avatar of RSayadi

ASKER

Yes, your post is correct. I just found out that it's a bit more complicated. I asked my question to soon.

Situation is as follow.

I have 3 tables.

The first one is as follow:
TABLE1.COLUMNA, TABLE1.COLUMNB, TABLE1.COLUMNC, TABLE1.COLUMND, TABLE1.COLUMNE, TABLE1.COLUMNF

All cells contain data

The second one:
TABLE2.COLUMNE, TABLE2.COLUMNF, TABLE2.COLUMNG, TABLE2.COLUMNH

Table 2 is missing records from table 1.

Table 3 contains data that must be updated into table 2 after table 2 is updated with the records from table 1.

Your syntax is correct but that is the last step.
Can you provide some sample data for tables 1 and 2 and what you expect it to look like after the first update, then sample data for table 3 and what you expect it to look like after the second update?
Avatar of RSayadi

ASKER

I used a INSERT INTO query for the fist part and the second part I used the provided suggestion.

INSERT INTO BASELINE ( COUNTRY, USERNAME, BASELINE_DATE, IN_SCOPE, USER_ACCOUNT_CREATED, HOME_DIR_CREATED, PROFILE_DIR_CREATED, GATE_DIR_CREATED )
SELECT [EUROPE_USERS].[COUNTRY], [EUROPE_USERS].[SAMACCOUNTNAME], [EUROPE_USERS].[INSERT_DATE], '0', '0', '0', '0', '0'
FROM EUROPE_USERS
WHERE ([EUROPE_USERS].[INSERT_DATE]=(SELECT Max([EUROPE_USERS].[INSERT_DATE]) FROM [EUROPE_USERS]))
AND
([EUROPE_USERS].[SAMACCOUNTNAME] NOT IN (SELECT [BASELINE].[USERNAME] FROM [BASELINE]));


Thank a lot
Umm... you are working with multiple people here.  Did you mean to accept Pete's solution rather than mine?  From the conversation here, I think you might have mistakenly clicked the "Accept" button under my post.
Avatar of RSayadi

ASKER

Shoot! Sorry about that!

I am doing 30 migrations in 7 countries and am so busy ATM that the 'll things tend to slip.