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';

錯誤原因不能將這張表數據查出來之後,而後又去更新這張表,只能先建個臨時表。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章