简体   繁体   English

如何修复我的 MySQL 错误 1093

[英]How do I fix my MySQL error 1093

How to fix this error如何修复此错误

[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)

Let me know让我知道

if you want to delete data of table then you use:如果要删除表的数据,则使用:

delete from [table] where [condition].从 [表] 中删除[条件]。

also for max you have to group your data first.同样对于最大值,您必须先对数据进行分组。

DELETE 
FROM
  user_log
WHERE
  UpdateDate < (SELECT MAX(UpdateDate) 
    FROM user_log 
    GROUP BY Email
    HAVING Email = user_log.Email)

when you want to use a condition on a group by then you have to use having instead of where.当你想在一个组上使用条件时,你必须使用 have 而不是 where。

change to;改成;

DELETE 
FROM
  user_log
WHERE
  UpdateDate < (SELECT MAX(UpdateDate) 
FROM user_log 
GROUP BY Email
HAVING Email = user_log.Email)

You cannot specify which fields are deleted in the DELETE statement, they all are.您不能指定在DELETE语句中删除哪些字段,它们都是。

I'm not 100% sure what your trying to do but you may be trying to do this我不是 100% 确定你想做什么,但你可能正在尝试这样做

DELETE FROM  user_log
WHERE  UpdateDate < (
    SELECT MAX(UpdateDate)     
    FROM user_log AS lookup     
    WHERE Email = lookup.Email
)

Hope this works for you.希望这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM