且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将多个表中的值插入单个表?

更新时间:2022-04-02 08:35:27

假设column1&第2列在表1中,第3列在表2中:

Assuming column1 & column2 are in table1, column3 in table2:

insert into table3 (field1, field2, field3)
select column1, column2, column3 from table1 t1 join table2 t2 on t1.table_id = t2.table_id


http://www.java2s.com/Tutorial/Oracle/0080__Insert-Update-Delete/Combinethreetableswithinsertintostatement.htm [ ^ ]

检查链接.它创建三个表,填充它们,然后从中填充第四个表.这将帮助您学习如何进行.
http://www.java2s.com/Tutorial/Oracle/0080__Insert-Update-Delete/Combinethreetableswithinsertintostatement.htm[^]

Check the link. It creates three tables, populate them and then populate the fourth table from them. This would help you learn how you should proceed.


您可以使用SELECT INTO来执行此操作
例如:
You can use SELECT INTO to do this
Ex:
SELECT Persons.LastName,Orders.OrderNo
INTO Persons_Order_Backup
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id



此处详细了解有关选择的信息. [



Read more about select into here[^]