mysql 查询 删除一起的时候 遇到 一个错误 临时表
DELETE FROM `t_record` WHERE num =20 AND id NOT IN (
SELECT id FROM `t_record` WHERE state =2
)
1 queries executed, 0 success, 1 errors, 0 warnings
查询:DELETE FROM `t_record` WHERE num =20 and id NOT IN ( select id from `t_record` where state =2 )
错误代码: 1093
You can't specify target table 't_record' for update in FROM clause
在MySQL中,写SQL语句的时候 ,可能会遇到You can't specify target table '表名' for update in FROM clause这样的错误,它的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值
加个临时表就行了
DELETE FROM `t_record` WHERE num =20 AND id NOT IN ( SELECT d.id FROM (SELECT * FROM `t_record` WHERE state =2) d )
UPDATE t_address SET use_it = 1 WHERE id = (SELECT temp.id FROM ( SELECT id FROM `t_address` WHERE openid = 'ol9QK41JT-RquRaTmFGECLcXwzDQ' AND use_it = 0 ORDER BY id DESC LIMIT 0,1) temp)
站长微信:xiaomao0055
站长QQ:14496453