MySQLMySQL 1093
MySQL 1093: Can't Specify Target Table for Update in FROM Clause
MySQL 1093 is raised when a DELETE or UPDATE statement uses the same table in the outer query and in a subquery in the FROM clause. MySQL does not allow modifying a table while reading from it in the same query.
Example Query
DELETE FROM users WHERE id IN (SELECT id FROM users WHERE active = 0); -- Cannot SELECT from the table being DELETEd
Common Causes
- 1Self-referencing subquery in DELETE or UPDATE on the same table
- 2Attempting to delete rows based on a condition queried from the same table
- 3ORM-generated query that creates this pattern
How to Fix It
Wrap the subquery in another level: DELETE FROM users WHERE id IN (SELECT id FROM (SELECT id FROM users WHERE active = 0) AS t). Or use a JOIN-based DELETE: DELETE u FROM users u JOIN (SELECT id FROM users WHERE active = 0) t ON u.id = t.id.
Need a reliable database?
Try Supabase — free PostgreSQL with a generous free tier. No credit card required.
Got a query causing this error?
Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.
Analyze My Query →