MySQL version: 5.5
MySQL报错:
You can't specify target table 'document_basic' for update in FROM clause
原因:MySQL不支持对同表同时更新+查询
解决方案:查询结果使用中间表接收,或者使用表连接# 错误:UPDATE tableSET column = #{newValue}WHERE id IN (SELECT id FROM table WHERE #{condition})# 使用中间表:UPDATE tableSET column = #{newValue}WHERE id IN (SELECT * FROM (SELECT id FROM table WHERE #{condition})temp)# 使用表连接:UPDATE tableJOIN table temp ON temp.id = table.idSET column = #{newValue}WHERE #{condition}