使用另一个表SQL中的列值更新一个表中的列的值?

时间:2022-09-21 15:16:48

I have two separate tables in my database. Table A has a column titled 'claimId', while Table B also has a column titled 'CLAIMID'. The column in Table A is completely empty, and I need to fill it with all of the values that are already in the 'CLAIMID' column in Table B. I've looked at multiple threads attempting to solve this issue, but to no avail. When I run the query that I have written on Table A, it says "0 rows affected". Is there something that I am missing when running this query? I am fairly new to SQL, so I am still trying to understand everything with it. I am using Microsoft SQL Server Management Studio, by the way. Here is the query that I am trying to run below:

我的数据库中有两个单独的表。表A有一个标题为'claimId'的列,而表B也有一个标题为'CLAIMID'的列。表A中的列是完全空的,我需要用表B中“CLAIMID”列中已有的所有值填充它。我已经查看了尝试解决此问题的多个线程,但无济于事。当我运行我在表A上编写的查询时,它会显示“0行受影响”。运行此查询时是否存在我遗漏的内容?我对SQL很新,所以我仍然试图用它来理解一切。顺便说一句,我正在使用Microsoft SQL Server Management Studio。这是我试图在下面运行的查询:

UPDATE a
SET a.claimId = b.CLAIMID
FROM TableA a
INNER JOIN TableB b
ON d.claimId = c.CLAIMID

1 个解决方案

#1


0  

Right after posting this question I've solved the problem. I feel kinda silly that I never thought about using INSERT INTO. Like I said, I'm fairly new to this. Here is the working query below:

发布此问题后,我已经解决了问题。我觉得有点傻,我从未考虑过使用INSERT INTO。就像我说的,我对此很新。以下是工作查询:

INSERT INTO TableA (claimId)
SELECT CLAIMID
FROM TableB

#1


0  

Right after posting this question I've solved the problem. I feel kinda silly that I never thought about using INSERT INTO. Like I said, I'm fairly new to this. Here is the working query below:

发布此问题后,我已经解决了问题。我觉得有点傻,我从未考虑过使用INSERT INTO。就像我说的,我对此很新。以下是工作查询:

INSERT INTO TableA (claimId)
SELECT CLAIMID
FROM TableB