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 祝福语驱散霉运的话简短