Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert into table with multiple values in subquery

Tags:

sql

insert

INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) 
VALUES (2222,(select tWaveID from @Table2))

I am using above query to insert into table. I know @Table2 has multiple tWaveID and that's why it is showing error :

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

How to resolve that and insert twaveID repeating RequestID as 2222 for all entries?

like image 474
Brijesh Kushwaha Avatar asked Dec 26 '22 14:12

Brijesh Kushwaha


1 Answers

Use the INSERT ... SELECT statement instead of a subquery:

INSERT INTO Reference_TB] ([RequestID] ,[WaveID]) 
(select 2222, tWaveID from @Table2)
like image 68
Sirko Avatar answered Jan 12 '23 14:01

Sirko