2013-09-23 60 views
0

當前表:SQL UPDATE值

id_product  id_shop  id_lang  description 
--------------------------------------------------------- 
1    1    est   black 
2    1    eng   brown 
3    1    rus   red 
1    2    est 
2    2    eng 
3    2    rus 

預期輸出:

id_product  id_shop  id_lang  description 
--------------------------------------------------------- 
1    1    est   black 
2    1    eng   brown 
3    1    rus   red 
1    2    est   black 
2    2    eng   brown 
3    2    rus   red 

我需要複製缺少從id_lang 1 '說明' 對id_lang 2爲各自的產品和語言。

我aquery但這超時和結果錯誤:

UPDATE `ps_product_lang` t1, `ps_product_lang` t2 
SET t1.description = t2.description 
WHERE t1.id_shop = 2 
AND t2.id_shop = 1 

我將不勝感激,如果你可以糾正我在哪裏,我錯了。

回答

0

這應該工作:

UPDATE `ps_product_lang` t1 join `ps_product_lang` t2 on 
t1.id_lang = t2.id_lang 
SET t1.description = t2.description 
WHERE t1.id_shop = 2 
AND t2.id_shop = 1 
+0

謝謝!首先它影響0行,但我設法糾正它(刪除和t1.id_shop = t2.id_shop): UPDATE'ps_product_lang' t1加入'ps_product_lang' t2在 t1.id_product = t2.id_product和t1.id_lang = t2 .id_lang SET t1.description = t2.description WHERE t1.id_shop = 2 AND t2.id_shop = 1 – popkutt

0

我認爲你可以使用id_lang列合併描述如下

UPDATE `ps_product_lang` t1 
INNER JOIN `ps_product_lang` t2 
ON t1.`id_lang` = t2.`id_lang` 
SET t1.`description` = t2.`description` 
WHERE t1.`description` IS NULL 

您可能需要更改IS NULL= ''如果列包含空值