简体   繁体   English

MS-Access如何从sql中的另一个表向表中的列添加值

[英]MS-Access how to add values to a column in a table from another table in sql

I'm trying to add values to a column in one of my tables and the value should be taken from another table that I have in the database. 我试图将值添加到我的一个表中的列,并且该值应从数据库中的另一个表中获取。 So let's say I have these two tables: 因此,假设我有以下两个表:

table1                           table2

| ID | in_reason         |             | ID | ...| in_reason |
|  2 |  promotion        |             | 7  | ...| 
|  5 |  replacing someone|             | 5  | ...| 
|  1 |  Hired            |             | 1  | ...| 
                                       | 2  | ...| 

Notice here that in table2, my in_reason column is empty and I want it to have the in_reasons from table1 where table2.ID is equal to table1.ID like this: 注意这里在table2中,我的in_reason列为空,我希望它具有table1中的in_reasons,其中table2.ID等于table1.ID,如下所示:

table2

| ID | ...| in_reason |
| 7  | ...| 
| 5  | ...| replacing someone
| 1  | ...| Hired
| 2  | ...| promotion

It should be something like this: 应该是这样的:

UPDATE Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID 
SET Table2.In_Reason = Table1.IN_Reason;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM