mysql批量删除语法异常&You can't specify target table for update in FROM clause错误

delete from jxfp_cx_xxxx t where t.id in(select max(id) from jxfp_cx_xxxx group by fpdm,fphm)

上面这条语句会报语法错误,near where t.id in

解决办法去掉别名

此后出现如下错误: You can't specify target table 'jxfp_cx_xxxx' for update in FROM clause

解决办法将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,sql server和oracle不会出现此问题。

delete from jxfp_cx_xxxx where id in (select id from (select max(id) as id from jxfp_cx_xxxx group by fpdm,fphm)a)

好啦,问题解决

 

posted @ 2016-08-16 19:46  暗夜心慌方  阅读(260)  评论(0)    收藏  举报