如何将多个表中的值插入单个表?
问题描述:
我有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[^]