SQL Error: Target Table in FROM Clause for UPDATE

you can't specify target table for update in from clause

SQL Error: Target Table in FROM Clause for UPDATE

Within SQL, attempting to modify a table using data derived from a subquery that references the same table within its `FROM` clause is generally prohibited. For example, an attempt to update salaries in a `employees` table based on data aggregated from the `employees` table itself within the update statement’s `FROM` clause would violate this principle. Instead, alternative approaches, such as subqueries in the `WHERE` clause or common table expressions (CTEs), should be employed. Direct modification through self-referencing within the `FROM` clause of an `UPDATE` statement is not allowed due to potential data inconsistencies and ambiguous evaluation order.

This restriction is vital for database integrity. It prevents circular dependencies that can lead to unpredictable results or deadlocks during updates. By enforcing this rule, the database management system (DBMS) ensures that modifications are performed in a controlled and predictable manner, upholding data consistency. This principle has been a standard practice in SQL databases for a considerable time, contributing to the reliability and predictability of data manipulation operations.

Read more