我正在使用mysql 5.0.77数据库使用查询:
Delete from IPADDRESS
where visitdate Not in (SELECT max(visitdate) FROM IPADDRESS WHERE USERNAME='MGSH0002')
and USERNAME='MGSH0002'
执行时出现此错误:
您无法在from子句
中指定要更新的目标表IPADDRESS
答案 0 :(得分:3)
当然不是最好的解决方案,但对于你的问题,这将解决问题:
delete i1 from
IPADDRESS i1,
IPADDRESS i2
where
i1.username = i2.username
and i1.username = 'MGSH0002'
and i1.visitdate < i2.visitdate
另一种更智能的解决方案是以下声明:
delete i1 from
IPADDRESS i1,
(select max(visitdate) visitdate from IPADDRESS where username = 'MGSH0002') temp
where
i1.username = 'MGSH0002'
and i1.visitdate < temp.visitdate
答案 1 :(得分:1)