Mysql更新關聯子查詢報錯

報錯內容:sql  1093 - You can't specify target table 'u' for update in FROM clausesql

錯誤緣由: if you're doing an UPDATE/INSERT/DELETE on a table, you can't reference that table in an inner queryspa

解決方法: (you can however reference a field from that outer table...)code

錯誤的sql語句orm

1 update gg_platform_navtree u set u.pid = (select id from gg_platform_navtree s where s.pid = u.pid and s.isleaf = 0 ) where u.isleaf = 1;

經過解決方案轉換後的sql語句blog

update gg_platform_navtree u set u.pid = (select id from (select * from gg_platform_navtree) s where s.pid = u.pid and s.isleaf = 0 ) where u.isleaf = 1;
相關文章
相關標籤/搜索