mysql Update subquery Table is Specified twice

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


mysql Update subquery Table is Specified twice



i try this subquery to decerese 1 i my quantity every time i execute this query , i think it will work on sqlServer but why its not working on mysql.
im getting this error
Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data



heres my code



Update tblbooks AS t1 set t1.Quantity = (Select t2.Quantity-1 from tblbooks AS t2 where t2.BookId = 123) where t1.BookId = 123




1 Answer
1



You don't need the subquery there - you can reassign a calculation on a column back to the same column:


UPDATE tblbooks
SET Quantity = Quantity - 1
WHERE BookId = 123





hahaha,i feel bad for me ,thank you
– Ivan
2 mins ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived