如何解决此错误
[Err] 1093 - You can't specify target table 'user_log' for update in FROM clause
DELETE
user_log
FROM
user_log
WHERE
UpdateDate < (SELECT MAX(UpdateDate)
FROM user_log
AS lookup
WHERE Email = user_log.Email)
让我知道
答案 0 :(得分:1)
如果要删除表的数据,请使用:
来自[table]的delete [condition]。
同样适用于max,您必须先对数据进行分组。
DELETE
FROM
user_log
WHERE
UpdateDate < (SELECT MAX(UpdateDate)
FROM user_log
GROUP BY Email
HAVING Email = user_log.Email)
当你想在一个组上使用条件时,你必须使用而不是在哪里。
答案 1 :(得分:0)
改为;
DELETE
FROM
user_log
WHERE
UpdateDate < (SELECT MAX(UpdateDate)
FROM user_log
GROUP BY Email
HAVING Email = user_log.Email)
您无法指定在DELETE
语句中删除哪些字段,它们都是。
答案 2 :(得分:0)
我不是100%确定你想要做什么,但你可能正在努力做到这一点
DELETE FROM user_log
WHERE UpdateDate < (
SELECT MAX(UpdateDate)
FROM user_log AS lookup
WHERE Email = lookup.Email
)
希望这适合你。