如何将多个表中的值插入单个表? [英] How to insert values from multiple tables to a single table?
本文介绍了如何将多个表中的值插入单个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3张桌子.我需要将第一个表中的3列值和第二个表中的1列值插入3third表.
I have 3 tables. i need to insert 3 column values from first table and 1 column value from second table into 3third table. what is the query for that????
推荐答案
假设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[^]
这篇关于如何将多个表中的值插入单个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文