Search code examples
mysqlsqlsql-updatemysql-error-1093

How do I update a column in 3rd row the same as a column in 2nd row in MySQL?


I'm doing it this way:

UPDATE products 
   SET products_image = (SELECT products_image 
                           FROM products 
                          WHERE products_id = 2) 
 WHERE products_id = 3;

...but get an error:

ERROR 1093 (HY000): You can't specify target table 'products' for update in FROM clause


Solution

  • UPDATE products p1, products p2 
    SET p1.products_image=p2.products_image 
    WHERE p1.id=3 AND p2.id=2;