0

我有一个简单的问题。我有两张桌子FROMTO. 我想将列Group从复制FROM到,TO但只复制与id_number. 它应该很简单,但我被卡住了。

insert into TO (Group)
   SELECT Group 
   FROM FROM
   WHERE FROM.id_number like TO.id_number

或者

INSERT INTO TO (Group)
   SELECT Group 
   FROM FROM
   WHERE id_number IN (SELECT id_number FROM TO)

这只是向表中添加了额外的列,它不会按照id_number...更新行。

任何的想法?

4

1 回答 1

2

您说“仅与 id_number 匹配的行”。这意味着update不是insert

update [TO] set [Group] = [FROM].[Group]
from [FROM]
inner join [TO] on [FROM].id_number = [TO].id_number
于 2012-12-12T20:37:53.773 回答