2015-09-15 25 views
1

之間加入我要做的有內表之間的大規模更新(200,000條記錄)JOIN:Mysql的內4臺

表1(數據源):

CODE | AVAILABILITY | PRICE 

表2(與只表「 CODE「):

ID | CODE 

表3(目標表1):

ID | PRICE 

表4(目標表2):

ID | AVAILABILITY 

我已到:

1) SELECT ID from Table2 WHERE table1.code=table2.code LIMIT 1 
2) UPDATE PRICE in Table3 WHERE table3.ID=table2.ID LIMIT 1 
3) UPDATE AVAILABILITY in Table4 WHERE table4.ID=table2.ID LIMIT 1 

如何實現這個只使用MySQL,在一個單一的查詢?

+0

不能完成。你需要一個存儲過程。 – duffymo

回答

0

使用此

UPDATE 
    table1 t1, table2 t2, table3 t3, table4 t4 
SET 
    t3.price=t1.price, t4.availability=t1.availability 
WHERE 
    t1.code=t2.code AND t2.id=t3.id AND t2.id=t4.id 
+0

這太簡單了,我沒有任何理由就搞砸了Inner Inner!謝謝... – Carmine