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.
精彩评论