2017-09-02 50 views
0

從一個查詢是否可以做到?如何從其他表中插入多個選定的行值到新表

要從一個表中插入多個選定的行信息到其它的表 像:

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; in one查詢

回答

4

是的,這可以通過使用

INSERT INTO Customers (register_no,CustomerName, City, Country) 
SELECT register_no SupplierName, City, Country FROM Suppliers where register_no in (1,3,10) 
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); 
+0

太謝謝你了@ B.Desai它的工作原理!!!!!! –

相關問題