SQL将数据从其他表插入表错误



我有以下问题:我的SQL Server 2019中有两个表。我需要用另一张表的日期更新一张表。

但我得到了这个错误:

子查询返回了多个值。当子查询跟在=、!=、<lt;=>gt;=或者当子查询用作表达式时。

表1:

ID and Group
1234-2
asdasd -2
dfgfdgdf-2

表2:

id, name, type ...

我需要将表2中的所有id添加到表1中,并始终为组添加值2

我尝试了这个查询

insert into dbo.table1 (Id, Group) 
values ((select [Id] from [customer].[dbo].[table2] where type = 4), '2')

试试这个

INSERT INTO dbo.table1 (Id, Group) 
SELECT [Id], '2' 
FROM [customer].[dbo].[table2] 
WHERE type = 4

最新更新