Consider a table with 2 fields:
tbl(Id int primary key,Name varchar(100))
Assume that this table contains one row with Id=3
and some unknown Name
.
Id | Name
---------------
3 | *****
I have an array of Id
s, for example: array(4,6,7,10)
How to put these Id
s with the Name
of row with Id=3
into this table with one query, So that the resulted table would be:
Id | Name
---------------
3 | *****
----------------
4 | *****
----------------
6 | *****
----------------
7 | *****
----------------
10 | *****
I can not use the Name
's value in the query.
I am thinking of a query like this:
insert into tbl(Id,Name) select (4,6,7,10),Name from tbl
You need 2 queries, 1st get the name and 2nd do the insert with multi row insert
INSERT INTO Table ( Column1, Column2 ) VALUES
( Value1, Value2 ), ( Value1, Value2 )