Why Views with Aggregates or GROUP BY Are Not Updatable in MySQL
MySQL restricts updatability of views to ensure that any update, insert, or delete performed through a view can be safely and unambiguously applied to exactly one underlying base table row. Views containing aggregate functions or GROUP BY clauses violate this rule.
Aggregate functions (SUM, AVG, COUNT, MAX, MIN) combine multiple rows into a single output row.
Because the result row does not correspond to any single row in the base table, MySQL cannot determine which original row should be updated.
Allowing updates on aggregated data could corrupt or misrepresent underlying table data.
Therefore, MySQL marks such views as non-updatable.
GROUP BY groups multiple base table rows into a single summary row.
Each result row represents a set of aggregated records, not a single tuple.
There is no direct row-level mapping back to the underlying table.
MySQL requires a one-to-one mapping for a view to support INSERT, UPDATE, or DELETE.
Views based on a simple SELECT from one table.
Views without aggregates, GROUP BY, DISTINCT, UNION, LIMIT, or joins.
Views where all columns are directly derived from base table columns.
In summary, views with aggregate functions or GROUP BY clauses cannot be updatable because their rows do not represent individual rows in the base table. As a result, MySQL cannot apply DML operations to them safely or meaningfully.