mysqldude
Error codes › 1093

MySQL & MariaDB error 1093: You can't specify target table for update in FROM clause

MySQLYou can't specify target table '…' for update in FROM clause
MariaDBTable '…' is specified twice, both as a target for '…' and as a separate source for data
Example from our test runs: You can't specify target table 'carts' for update in FROM clause (5.6.51)

MySQL won't let an UPDATE or DELETE read the same table in a subquery that it is modifying. MariaDB (10.3.2+) allows it; on MySQL you materialise the subquery first or use a multi-table statement.

MySQLMariaDB
SymbolER_UPDATE_TABLE_USEDER_UPDATE_TABLE_USED
SQLSTATEHY000HY000
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

You can't specify target table 'emp' for update in FROM clause. A statement like DELETE FROM emp WHERE salary < (SELECT AVG(salary) FROM emp) reads and changes emp at the same time; MySQL refuses rather than risk the subquery seeing half-changed data.

Why it happens

  • UPDATE or DELETE with a WHERE … IN (SELECT … FROM same_table) or a scalar subquery on the same table: removing duplicates, deleting below-average rows, “keep the latest row per group”.
  • It is MySQL-only: our tests show 1093 on every MySQL version from 5.6 to 9.x, while MariaDB 10.6–11.8 runs the same statement correctly (supported since MariaDB 10.3.2).

How to fix it

  • Wrap the subquery in a derived table so it is computed before the change starts: DELETE FROM emp WHERE salary < (SELECT a FROM (SELECT AVG(salary) AS a FROM emp) x);
  • Or use a multi-table statement: DELETE e FROM emp e JOIN (SELECT AVG(salary) AS a FROM emp) x ON e.salary < x.a;
  • On MySQL 8.0 the optimizer may merge a simple derived table back into the outer query; if the error returns, add /*+ NO_MERGE(x) */ or use a temporary table.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database and the test data:

    CREATE DATABASE demo;
    USE demo;
    CREATE TABLE emp (id INT PRIMARY KEY, salary INT);
    INSERT INTO emp VALUES (1, 100), (2, 300), (3, 200);
  2. Run:

    DELETE FROM emp WHERE salary < (SELECT AVG(salary) FROM emp);

You get: You can't specify target table 'emp' for update in FROM clause(9.7.4)

Verified fixes

  1. Wrap the subquery in a derived table so it is materialised first

    DELETE FROM emp WHERE salary < (SELECT a FROM (SELECT AVG(salary) AS a FROM emp) x);
    SELECT id FROM emp ORDER BY id;
  2. Or rewrite as a multi-table DELETE ... JOIN

    DELETE e FROM emp e JOIN (SELECT AVG(salary) AS a FROM emp) x ON e.salary < x.a;
    SELECT id FROM emp ORDER BY id;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
UPDATE/DELETE with a subquery that reads the same table
repro
✓ 1093✓ 1093✓ 1093✓ 1093✓ 1093≠≠≠≠
Wrap the subquery in a derived table so it is materialised first
fix
✓✓✓✓✓✓✓✓✓
Or rewrite as a multi-table DELETE ... JOIN
fix
✓✓✓✓✓✓✓✓✓
UPDATE/DELETE with a subquery that reads the same table repro
MySQL 5.6✓ 10935.7✓ 10938.0✓ 10938.4✓ 10939✓ 1093
MariaDB 10.6≠10.11≠11.4≠11.8≠
Wrap the subquery in a derived table so it is materialised first fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Or rewrite as a multi-table DELETE ... JOIN fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (1)
  • UPDATE/DELETE with a subquery that reads the same table (MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1093 did not occur

Related errors

  • 1242 ER_SUBQUERY_NO_1_ROWexplained
  • 1443 ER_VIEW_PREVENT_UPDATE

Where this error shows up in our guides

  • UPDATE with a join · UPDATE ... WHERE col IN (SELECT ... FROM same table): 1093 on MySQL, allowed on MariaDB MySQL 5.6 5.7 8.0 8.4 9
How the message changed between versions
MariaDB fromSymbolMessage
5.5.68ER_UPDATE_TABLE_USEDYou can't specify target table '%-.192s' for update in FROM clause
10.0.38ER_UPDATE_TABLE_USEDTable '%-.192s' is specified twice, both as a target for '%s' and as a separate source for data