如何将其他表中的多个选定行值插入到新表中

时间:2017-09-02 05:06:55

标签: php mysql sql-server oracle

  

从一个查询中可以做到吗?

将多个选定的行信息从一个表插入到另一个表中 喜欢:

Customers (register_no,CustomerName, City, Country)
Suppliers(register_no,SupplierName, City, Country)

INSERT INTO Customers (register_no,CustomerName, City, Country) SELECT register_no SupplierName, City, Country FROM Suppliers where register_no=10;

但有一次可以选择register_no = 1,register_no = 3,register_no = 10; 在一个查询中

2 个答案:

答案 0 :(得分:4)

是的,可以在

中使用
INSERT INTO Customers (register_no,CustomerName, City, Country)
SELECT register_no SupplierName, City, Country FROM Suppliers where register_no in (1,3,10)

答案 1 :(得分:2)

您可以使用IN子句。

INSERT INTO Customers (register_no,CustomerName, City, Country)
SELECT register_no SupplierName, City, Country FROM Suppliers where register_no IN (1,3,10);