Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query to update column using a secondary table 1

Status
Not open for further replies.

chaos18

IS-IT--Management
Dec 31, 2002
32
US
I am creating a query that uses a secondary table to update the main table, the catch is that only two columns are alike and then there will be a third after the main table is updated. What i would like to do is have the query look at the two columns that are alike, and then match the information from the third. If that doesn't make much sense then look at the diagram below

MAIN TABLE:
_____________________________________________________
|To be updated|Matching column #1|Matching column #2|
|'new info.' | 123456 | 654321 |

SECONDARY TABLE:
_____________________________________________________
UPDATE Info. |Matching column #1|Matching column #2|
|'new info.' | 123456 | 654321 |


This is a rough sketch of what is supposed to happen. Of course in each table there are more columns but i kept it as simple as possible. Any ideas on how i should do this query


Thomas Gunter,A+, Network+
Network Administrator
 
UPDATE Secondary INNER JOIN Main ON (Secondary.Column2 = Main.Column2) AND (Secondary.Column1 = Main.Column1) SET Main.Info = [Secondary].[Info];

Create 2 Tables, named MAIN and SECONDARY.

Both tables have 3 Fields, named INFO, COLUMN1 and COLUMN2.

In both tables populate Column1 and Column2 similarly to your example, do a few records.

In the Secondary table, in the Info field, type in Record1, Record2 etc. Leave the Info field blank in the Main table.

Paste the above query into a new query's SQL. Run it, the Main table should now have Record1, Record2 etc in its Info field.

If you're happy with this, adapt the query to your actual tables. For additional fields follow what I have done for the Info field.

Let me know how you get on.


 
WoW! i have to say this query worked like a charm!!! i thankyou greatly for the help and if there's anything i can do to repay you i'll be happy to help


Thanks again
Thomas Gunter,A+, Network+
Network Administrator
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top