mysql中You can’t specify target table for update in FROM clause错误解决方法
mysql中Youcan'tspecifytargettableforupdateinFROMclause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。例如下面这个sql:
deletefromtblwhereidin
(
selectmax(id)fromtblawhereEXISTS
(
select1fromtblbwherea.tac=b.tacgroupbytacHAVINGcount(1)>1
)
groupbytac
)
改写成下面就行了:
deletefromtblwhereidin
(
selecta.idfrom
(
selectmax(id)idfromtblawhereEXISTS
(
select1fromtblbwherea.tac=b.tacgroupbytacHAVINGcount(1)>1
)
groupbytac
)a
)
也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。
热门推荐
10 喜得孙子祝福语简短唯美
11 婚礼祝福语简短朴实大众
12 员工周年祝福语大全简短
13 家长回复节日祝福语简短
14 简短生日祝福语老同学
15 夜雨祝福语简短10字
16 蛋糕祝福语简短闺蜜
17 部门过年祝福语简短独特
18 简短精炼的结婚祝福语