Error 1349 is raised when a view definition contains a subquery in the FROM clause without an explicit TEMPTABLE algorithm.
MySQL Error 1349 ER_VIEW_SELECT_DERIVED_UNUSED appears when a view’s SELECT includes a subquery in the FROM clause. Add ALGORITHM=TEMPTABLE to the CREATE or ALTER VIEW statement or rewrite the query to remove the derived table to resolve the error.
View's SELECT contains a subquery in the FROM clause
Error 1349 fires when MySQL parses a CREATE VIEW or ALTER VIEW statement whose SELECT block contains a derived table subquery in the FROM clause. The parser cannot merge such a view, so it rejects the definition unless a TEMPTABLE algorithm is declared.
The error was introduced in MySQL 5.7.7 and persists through MySQL 8.0. Its SQLSTATE is HY000 (general error). Clearing it is critical because the view will not be created or updated, blocking dependent queries and applications.
The primary trigger is a derived table in the FROM clause, such as FROM (SELECT ... ) AS dt
. MySQL’s default MERGE algorithm cannot handle this construct.
The error also appears when the view omits or overrides ALGORITHM=TEMPTABLE, or when CREATE VIEW tries to wrap an existing view that already uses MERGE.
The most reliable solution is to specify ALGORITHM=TEMPTABLE
in the CREATE VIEW or ALTER VIEW statement. This tells MySQL to store the derived table in a temporary table at execution time instead of merging it.
Alternatively, rewrite the statement to avoid the subquery entirely and join the base tables directly, thereby keeping the default MERGE algorithm.
Scenario 1 – Analytics view with inline aggregation – add TEMPTABLE or move the aggregation into a base table or materialized table.
Scenario 2 – Layered views where an upper view references a lower view using a derived table – collapse the layers into a single view or convert one layer to a table.
Always choose ALGORITHM=TEMPTABLE when you must keep a derived table in the view definition. Document this choice in version control.
Use Galaxy’s editor linting to surface view-creation errors before they reach production, and rely on its schema-aware AI copilot to suggest valid view algorithms.
Error 1356 (HY000) – Cannot use stored function/trigger in this context – remove or refactor the function/trigger call.
Error 1359 – View’s SELECT contains a subquery in the SELECT clause – specify TEMPTABLE or remove the subquery.
A subquery wrapped in parentheses and aliased inside FROM forces a derived table that MERGE cannot process.
When no ALGORITHM is declared, MySQL tries MERGE by default. Derived tables are incompatible, so the statement fails.
A new view referencing another view that already contains a derived table propagates the same limitation unless rebuilt with TEMPTABLE.
After upgrading from 5.6 to 5.7.7+, previously valid views with derived tables start failing because the stricter rule is now enforced.
Raised when the SELECT list of a view contains a subquery; solved with TEMPTABLE or query rewrite.
Indicates a CHECK OPTION failure because the view’s WHERE clause is not satisfied by inserted or updated rows.
Occurs when the DEFINER lacks SELECT privileges on underlying tables; grant the required rights or change the DEFINER.
Yes, as long as you declare ALGORITHM=TEMPTABLE or rewrite the query for MySQL 8.0 CTE support. Otherwise, Error 1349 will occur.
TEMPTABLE can add overhead because MySQL materializes the result, but the effect is usually minor for small data sets. Profile performance before production use.
MariaDB shares similar view-processing rules, but the exact error code may differ. Test view creation after migrations.
Galaxy’s SQL editor flags unsupported view constructs in real time, suggests ALGORITHM=TEMPTABLE, and autogenerates a corrected statement.