我必须插入一些来自不同表的动态项目
插入(field1,field2,field3)值(<select query fetching one record>,<static value>, <select query fetching multiple records, need to insert one by one>
)
如何在此处在数据库中用foreach插入?请帮忙!
样本数据:
插入(field1,field2,field3)值(select myname from table1',0, select payment[1] from table2
);
插入(field1,field2,field3)值(select myname from table1',0, select payment[2] from table2
);
答案 0 :(得分:0)
如果要插入表中的内容是其他查询的组合结果,则可以仅将INSERT INTO
与SELECT
和UNION
一起使用。
像这样
INSERT INTO your_table (column1, column2, column3)
SELECT column1, column2, column3
FROM table1
UNION ALL
SELECT column1, column2, column3
FROM table2