带有子选择的sql插件

时间:2013-12-13 16:00:09

标签: sql db2

我有SQL查询,如下所示:

INSERT INTO TABEL1 (val1,val2,val3,....,val10,val11)
VALUES (......
(SELECT VAL1 FROM TABELE2 WHERE...),
(SELECT VAL2 FROM TABELE2 WHERE...),
(SELECT VAL3 FROM TABELE2 WHERE...)
.....)

你可以建议更好地实现这样的插入吗?

1 个答案:

答案 0 :(得分:1)

INSERT INTO table1 (val1,val2,val3,....,val10,val11)
SELECT val1, val2, val3, ...
FROM table2 
WHERE...

如果你想要一些额外的常量,那么只需将它们添加到选择:

INSERT INTO table1 (val1, val2, val3, ...., val10, val11)
SELECT val1, val2, val3, 'some info', 42, ...
FROM table2 
WHERE...