1093 🐬 MySQL

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

  1. Wrap in a derived table: … IN (SELECT id FROM (SELECT …) AS t)
  2. Rewrite with a self JOIN

Detailed fix by platform

MySQL

  1. 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

  1. Statement — Does the subquery read the target table?
  2. 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.