mysql中的一个特殊问题:You can’t specify target table ‘abc’ for update in FROM clause
2015-01-29 11:07
736 查看
今天在处理数据的时候,需要update医院的行政编码。在
为了解决这个问题,首先使用了
得到
当我以为剩下的工作,用如下的updata语句就可以解决的时候,
却报错了:
意思应该就是,你要update一个表的时候,不能让这个表出现在
解决方法也很愚蠢,新建一个
医院(hospital)表,医院所在地一般记做“海淀,东城”,而在
行政区码(codenum)中,却是“海淀区,东城区”
为了解决这个问题,首先使用了
Mysql中的
CONCAT函数。
[code]SELECT hospital.district FROM hospital, codename WHERE codename.`name` IN( SELECT CONCAT(district,"区") FROM hospital)
得到
当我以为剩下的工作,用如下的updata语句就可以解决的时候,
[code]UPDATE hospital, codename SET hospital.qu=codename.num WHERE hospital.qu IN( SELECT hospital.district FROM hospital, codename WHERE codename.`name` IN( SELECT CONCAT(district,'区') FROM hospital) )
却报错了:
You can't specify target table 'hospital' for update in FROM clause
意思应该就是,你要update一个表的时候,不能让这个表出现在
FROM里面(应该是会导致死循环思密达)。
解决方法也很愚蠢,新建一个
tmp表。然后用这个表进行
UPDATE
[code]CREATE TABLE tmp AS SELECT hospital.district, codename.num FROM hospital, codename WHERE codename.`name` IN( SELECT CONCAT(district,'区') FROM hospital)
相关文章推荐
- mysql 一个较特殊的问题:You can't specify target table 'wms_cabinet_form' for update in FROM clause
- mysql update语句问题:You can't specify target table 'user' for update in FROM clause
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- mysql中You can't specify target table for update in FROM clause错误
- MYSQL:You can’t specify target table for update in FROM clause 解决办法
- MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法
- MySQL:You can’t specify target table ‘A’ for update in FROM clause
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- MYSQL:You can’t specify target table for update in FROM clause 解决办法
- mysql Error Code: 1093. You can't specify target table 'base_extend' for update in FROM clause 0.001
- MySQL:You can’t specify target table ‘A’ for update in FROM clause
- mysql中You can't specify target table for update in FROM clause错误
- mysql中You can't specify target table for update in FROM clause错误
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- mysql中You can't specify target table for update in FROM clause错误
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- Mysql You can't specify target table for update in FROM clause
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- mysql中You can't specify target table for update in FROM clause错误 转