7

ここで間違ったステートメントを説明するために、多くの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
)

したがって、基本的に挿入する値はさまざまなサブクエリから取得されますが、そのような動作を実現することは可能ですか?

4

2 に答える 2

16
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
于 2012-06-05T16:36:40.843 に答える
1

selectステートメントを使用して挿入を行うことはできますか?

INSERT INTO MYTABLE
SELECT (SOMEVALUE,
    SOMEVALUE,
    T1.ID,
    T2.ID
)
FROM ANOTHERTABLE T1
JOIN YETANOTHERTABLE T2
    ON T1.BLAH = T2.BLAH
WHERE condition1...
于 2012-06-05T16:39:58.257 に答える