Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why update and select both is not working with same table

In this query i want to update those records which is latest posted.But my this query is not working please help me what the reason ???

Error :--You can't specify target table 'beevers_products' for update in FROM clause

update beevers_products set product_name='my_product_name' where posted_date in (SELECT posted_date FROM `beevers_products` order by posted_date asc limit 1)
like image 461
Salman Ahmad - Mean Developer Avatar asked Nov 13 '22 11:11

Salman Ahmad - Mean Developer


1 Answers

Check this:

UPDATE beevers_products 
SET product_name = 'my_product_name' 
WHERE posted_date = (SELECT posted_date 
                     FROM beevers_products
                     ORDER BY posted_date DESC limit 1)
like image 82
Furkat U. Avatar answered Nov 15 '22 05:11

Furkat U.