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 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特