Insert into with multiple subqueries as values

sql, sql-server, sql-server-2005

Solution

insert into mytable (columns)
select somevalue, somevalue, a.id, b.id, c.id
from
 othertable1 a
 cross join othertable2 b
 cross join othertable3 c
where
 a ... condition
 b ... condition
 c ... condition

Problem

Lets suppose I've to insert into a table with many fk, just to explain here below the wrong statement: ``` insert into mytable values ( somevalue ,somevalue ,select id from othertable1 where ...condition ,select id from othertable2 where ...condition ,select id from othertable3 where ...condition ) ``` so basically values to insert comes from different subqueries, is it possible to achieve such a behavior ?

Original source

Related problems