2017-01-02 18 views
0

我運行以下查詢多次:MySQL的插入多行與一個選擇

insert ignore into temp_table (ID, Price, Stock, Vendor) 
select ID, Price_Vendor_A, Stock_Vendor_A, 'Vendor_A' from temp_table2 limit 1; 
insert ignore into temp_table (ID, Price, Stock, Vendor) 
select ID, Price_Vendor_B, Stock_Vendor_B, 'Vendor_B' from temp_table2 limit 1; 

的2個選擇查詢導致在同一行。

有沒有更快的方法來做到這一點?

回答

0

繼將是最快的方式。取消多個選擇。

​​
+0

查詢似乎工作,但這只是創建了兩個排,與股票和供應商A的價格如何使用您的查詢以創建兩行,一行與供應商A和一個與供應商B? – Vidarrus

+0

糟糕,你能告訴我在哪裏使用這個SQL嗎?在代碼或在過程/功能/ SQL編輯器? – meet

+0

我在MySQL中創建一個過程。我的sqleditor被稱爲HeidiSQL。 – Vidarrus

0

我不知道這是否會更快,但你可以嘗試插入單個UNION查詢:

insert ignore into temp_table (ID, Price, Stock, Vendor) 
select ID, Price_Vendor_A, Stock_Vendor_A, 'Vendor_A' from temp_table2 limit 1 
union all 
select ID, Price_Vendor_B, Stock_Vendor_B, 'Vendor_B' from temp_table2 limit 1