MySQL throws Error 1335 when a stored program contains a scalar subquery in a context the engine still does not support.
MySQL Error 1335: ER_SP_SUBSELECT_NYI – Subquery value not supported – appears when a stored procedure, function, trigger, or event uses a scalar subquery where only constants or variables are allowed. Rewrite the routine with SELECT … INTO or upgrade to a newer MySQL version to resolve the issue.
Subquery value not supported
MySQL raises Error 1335 with message “Subquery value not supported” when a stored procedure, function, trigger, or event contains a scalar subquery expression that the parser cannot translate into an executable plan.
The error belongs to SQLSTATE 0A000, meaning the requested feature is not implemented. MySQL stops compilation immediately, preventing the routine or statement from being created or executed.
The primary trigger is placing a subquery where only literals or user variables are permitted, such as the RETURN clause of a stored function, a SET var = (SELECT …) assignment, or a DEFAULT parameter value.
Older versions before 8.0.22 also emit this error if the subquery returns multiple rows in a scalar context. Upgrading or refactoring removes the limitation in most cases.
Rewrite the routine to move the subquery into a standalone SELECT … INTO statement executed before the value is used.
For RETURN clauses, store the result in a local variable, then return that variable. This avoids placing the subquery directly in the expression.
If possible, upgrade the server to MySQL 8.0.34 or later, where several subquery restrictions have been relaxed.
Creating a function like CREATE FUNCTION f() RETURNS INT RETURN (SELECT COUNT(*) FROM orders);
fails. Rewrite as a BEGIN block, SELECT into a variable, then RETURN the variable.
Inside procedures, SET total = (SELECT SUM(amount) FROM payments);
errors out. Use SELECT SUM(amount) INTO total FROM payments;
instead.
Parameter DEFAULT values cannot contain subqueries. Compute the value in the caller or within the body of the routine.
Always separate subqueries into explicit SELECT … INTO statements when targeting legacy MySQL servers.
Test stored programs on a staging server running the same version as production to catch unsupported-feature errors early.
Track MySQL release notes and schedule upgrades; newer versions gradually lift subquery limitations, letting you simplify code.
Error 1242 – “Subquery returns more than 1 row” indicates logic issues; fix by aggregating or adding LIMIT 1.
Error 1336 – “ER_SP_WRONG_NO_OF_ARGS” arises from calling a routine with the wrong argument count; supply correct parameters.
Error 1415 – “ER_NONEXISTING_PROC_REFERENCED” appears when a trigger references a missing procedure; create the routine or update the trigger definition.
Placing a subquery directly inside the RETURN clause of a stored function triggers the feature-not-implemented error.
Using SET var = (SELECT …) or DECLARE var DEFAULT (SELECT …) is unsupported in affected MySQL versions.
MySQL prohibits subqueries where only constants can appear, such as parameter defaults or trigger conditions.
Happens when a scalar subquery produces multiple rows; limit or aggregate to one row.
Raised when the argument count in a routine call does not match its definition.
Occurs when a trigger references a procedure that no longer exists.
Yes. Many subquery restrictions were relaxed in 8.0.22 and later, allowing subqueries in RETURN and variable assignments.
Upgrading removes the limitation, but you must re-create the routines or run ALTER FUNCTION/PROCEDURE
so they compile under the new engine.
Galaxy’s real-time linting flags unsupported subqueries while you type, letting you refactor before the code reaches production.
No. That situation triggers Error 1242. Error 1335 occurs even with a single-row subquery if placed in an unsupported context.