插入多个子查询作为值

Fel*_*ano 2 sql sql-server sql-server-2005

让我们假设我要插入一个包含许多fk的表,只是为了在下面解释错误的声明:

insert into mytable
values
(
somevalue
,somevalue
,select id from othertable1 where ...condition
,select id from othertable2 where ...condition
,select id from othertable3 where ...condition
)
Run Code Online (Sandbox Code Playgroud)

所以基本上插入的值来自不同的子查询,是否有可能实现这样的行为?

小智 10

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
Run Code Online (Sandbox Code Playgroud)