问一个mysql语句的问题
我有这样一个mysql语句:delete from hotelinformation where CreateTime <>(select CreateTime from hotelinformation order by CreateTime desc limit 1)
运行以后报错为:You can't specify target table 'hotelinformation' for update in FROM clause请问这是什么错误啊
------解决方案--------------------limit 是非标准的sql
去掉 limit 1 试试
后面的子查询用order by 似乎没什么必要,又不做显示
------解决方案--------------------你在对一个表做修改删除时,这个表是不能同时出现在条件子句里的,这是个逻辑问题
比如
delete from table1 where ... (select ... from table2 order by CreateTime desc limit 1)
就是可以的
而
delete from table1 where ... (select ... from table1 order by CreateTime desc limit 1)
就是不可以的