从另一行同一个表更新表行

时间:2017-03-06 10:23:42

标签: mysql copy row

table image with columns and rows here

你好,我想用language_code = ro来更新所有行与使用language_code = en(只有name,meta_description,short_description,description和head_title)的行一样,我试过了

UPDATE lc_products_info lc LEFT JOIN lc_products_info lc2 ON (lc.product_id=lc2.product_id AND lc.name='' AND lc2.language_code='en') SET lc.name = lc2.name;

但它似乎删除了leanguage code = en的行内容,如果有人可以帮助我....提前感谢

2 个答案:

答案 0 :(得分:0)

使用Where

UPDATE lc_products_info lc
LEFT JOIN lc_products_info lc2 ON lc.product_id=lc2.product_id AND lc2.language_code='en' SET lc.name = lc2.name
WHERE lc.name=''
AND lc.language_code='ro';

答案 1 :(得分:0)

UPDATE lc SET name=lc2.name FROM lc_products_info lc LEFT JOIN lc_products_info lc2 ON lc.product_id=lc2.product_id AND lc.name='' AND lc2.language_code='en'