Mysql: Table 'name' is specified twice, both as a target for 'UPDATE' and as a separate source for data
2015-04-02 17:09
393 查看
mysql在执行删除、更新的时候,可能会出现这样的错误,比如你写了类似下面的sql:
or
这个时候就会出现Table 'xxx' is specified twice这样的错误,不知道mysql为什么会做这样的冻结,知道的大神请给个链接。
要解决这个问题很简单,既然table 'xxx'不能放到子查询里面,那就做一个缓存表呗。
这样就没有问题了。
UPDATE MYTABLE SET COL=COL+1 WHERE ID IN (SELECT ID FROM MYTABLE WHERE OTHERCOL=0)
or
DELETE FROM MYTABLE WHERE ID IN (SELECT ID FROM MYTABLE WHERE OTHERCOL=0)
这个时候就会出现Table 'xxx' is specified twice这样的错误,不知道mysql为什么会做这样的冻结,知道的大神请给个链接。
要解决这个问题很简单,既然table 'xxx'不能放到子查询里面,那就做一个缓存表呗。
DELETE FROM MYTABLE WHERE ID IN (SELECT * FROM (SELECT ID FROM MYTABLE WHERE OTHERCOL=0) AS TEMP)
这样就没有问题了。
相关文章推荐
- Mysql: Table name is specified twice, both as a target for UPDATE and as a separate source for data
- mysql报Table 'XXX' is specified twice, both as a target for 'UPDATE'....
- mysql:ERROR 1194 (HY000): Table 'user' is marked as crashed and should be repaired
- Mysql错误:Table 'xxx'is marked as crashed and last (automatic) repair failed
- Mysql错误:Table 'xxx'is marked as crashed and should be repaired 错误编号:145
- Data for Source Column 3(’Col3’) is too large for the specified buffer size.
- mysql错误:Table XXX is marked as crashed and should be repaire
- Demo: Fill and Save PDF Form online(also can add more function,such as email and save data to database ),Adobe Reader is enough
- EJB3: Mapping of 1-to-1 relationships when primary key in the source table is also a foreign key for the target entity
- compiled for a little endian system and target is big endian
- mysql 数据库程序出现Table xxx is marked as crashed and should be repaired
- mysql错误:Table XXX is marked as crashed and should be repaired
- mysql错误:Table XXX is marked as crashed and should be repaire
- mysql错误:Table XXX is marked as crashed and should be repaired
- mysql 出现表损坏解决方法:table 'xxx' is marked as crashed and should be repaired
- [MySQL]快速解决"is marked as crashed and should be repaired"故障
- Android: Simplified source code for parsing and working with XML data and web services in Android
- mysql错误:……is marked as crashed and should be repai
- [异常]Support for specifying both a day-of-week AND a day-of-month parameter is no
- MySql.Data.MySqlClient.MySqlException: The user specified as a definer ('root'@'%') does not exist