MySQL ERROR 1093 (HY000): You can't specify target table 'x' for update in FROM clause
An UPDATE/DELETE uses a subquery that reads from the same table, which MySQL doesn’t allow directly.
Seen on:
MySQL
Meaning
MySQL can’t modify a table while selecting from it in a subquery. Wrap the subquery in a derived table or use a JOIN.
Common causes
- DELETE … WHERE id IN (SELECT … FROM same_table)
- UPDATE with self-referencing subquery
⚡ Quick fix
- Wrap in a derived table: … IN (SELECT id FROM (SELECT …) AS t)
- Rewrite with a self JOIN
Detailed fix by platform
MySQL
DELETE u FROM users u JOIN (SELECT MIN(id) id, email FROM users GROUP BY email) k ON k.email = u.email AND u.id <> k.id;
How to diagnose
- Statement — Does the subquery read the target table?
- Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026