'SQL Insert Data to Table from other Table error
I have the following problem: I have 2 tables in my SQL Server 2019. I need to update one table with the date from the other table.
But I get this error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Table 1:
ID and Group
1234-2
asdasd -2
dfgfdgdf-2
Table 2:
id, name, type ...
I need to add all the ids from table 2 to the table 1 and add always for the group the value 2
I tried with this query
insert into dbo.table1 (Id, Group)
values ((select [Id] from [customer].[dbo].[table2] where type = 4), '2')
Solution 1:[1]
Try this
INSERT INTO dbo.table1 (Id, Group)
SELECT [Id], '2'
FROM [customer].[dbo].[table2]
WHERE type = 4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marc_s |
