mysql执行SQL语句时,出现You can't specify target table '表名' for update in FROM clause错误

错误语句:
update tenant_menu set parent_id = (select id from tenant_menu where menu_code = '6') where menu_code = '6_7';


正确语句:

update tenant_menu set parent_id = (select a.id from (select tmp.* from tenant_menu tmp) a where menu_code = '6') where menu_code = '6_7';

错误原因不能将这张表数据查出来之后,而后又去更新这张表,只能先建个临时表。

你可能感兴趣的:(mysql)