Unable to execute below query
Update tbl SET alias_seq= (Select seq from tbl where analysed_object =
'data' order by seq LIMIT 1)
getting below error
#1093 - You can't specify target table 'tbl' for update in FROM clause
You cannot update the rows from the same data source which your sub query refers to.
Modify your query to this
UPDATE tbl SET alias_seq= (SELECT * FROM (Select seq from tbl where analysed_object = 'data' order by seq LIMIT 1) as X)
Here nested sub query makes a temporary table. So it doesn’t count as the same table you’re trying to update data from. In other words in MySQL
, you can’t modify the same table which you use in the SELECT
part.
You may refer here for more information UPDATE Syntax.