UPDATE MenuPosition
SET Position = (SELECT Position FROM MenuPosition WHERE MenuId ='2')
WHERE MenuId ='1'
当我们使用查询时,我们会收到错误:
You can't specify target table 'MenuPosition' for update in FROM clause
请告诉我我的错误在哪里怎么样?
答案 0 :(得分:0)
烨。这是MySQL的一个限制。相反,请使用join
:
UPDATE MenuPosition mp cross join
(SELECT Position FROM MenuPosition WHERE MenuId ='2'
) mp2
SET mp.Position = mp2.Position
WHERE MenuId = '1';
答案 1 :(得分:0)
另一种方法
UPDATE MenuPosition as tbl1
JOIN MenuPosition as tbl2 on
tbl1.MenuId = '1'
AND tbl2.MenuId = '2'
SET tbl1.Position = tbl2.Position