Christopher Wlp Bianchi Christopher Wlp Bianchi - 6 months ago 13
SQL Question

UPDATE MySQL query error "Subquery returns more than 1 row"

I'm trying to achieve this query but I got an error:

UPDATE ps_product_lang
SET name=(select name from ps_product_lang_backup where id_lang=2)
WHERE id_lang = 3


But I got the
Subquery returns more than 1 row


Probably I must use JOIN but I'm really new to MySQL and cannot do myself.

What i'm trying to do is simple: i have in my database 3 languages, wish to copy data from one language (english id_lang 2) to paste in another (russian, id_lang 3)

Answer

I assume the table also has a product_id column that is unique for a product.

You need to tell the database to pick the english name for the same product.

UPDATE ps_product_lang
SET name=(select name from ps_product_lang_backup 
           where id_lang=2 
             and ps_product_lang.product_id = ps_product_lang_backup.product_id)
WHERE id_lang = 3