Sackling
Sackling

Reputation: 1820

joining table on itself to copy column matching same product

I am trying to copy a product description to the same product_id but in a different language (USA and Canada) both are in english so that is why I am copying them over.

I am however getting 0 rows updated. Here is my sql:

UPDATE products_description pd1  
JOIN products_description pd2 on pd1.products_id = pd2.products_id and pd2.language_id = 3
SET pd1.products_description_second = pd2.products_description_second
WHERE pd2.language_id = 1

When I run the sql though i get 0 rows affected.

Here is a picture of the table: https://i.sstatic.net/5ngmJ.png

Upvotes: 0

Views: 27

Answers (1)

DBug
DBug

Reputation: 2566

Think problem is testing language_id. You're joining on pd2.language_id = 3 and using WHERE pd2.language_id = 1, so trying to join the rows on language_id '3' where language_id is '1'. One of these should probably be pd1.language_id.

Upvotes: 0

Related Questions