开发者

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 
    WHE开发者_开发问答RE 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.


I'm not 100% sure what your trying to do but you may be trying to do this

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

Hope this works for you.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜