Common SQL Errors

MySQL Error 1335: ER_SP_SUBSELECT_NYI – Subquery value not supported (Fix Guide)

Galaxy Team
August 6, 2025

MySQL throws Error 1335 when a stored program contains a scalar subquery in a context the engine still does not support.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1335?

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.

Error Highlights

Typical Error Message

Subquery value not supported

Error Type

Feature Limitation Error

Language

MySQL

Symbol

ER_SP_SUBSELECT_NYI

Error Code

1335

SQL State

0A000

Explanation

Table of Contents

What is MySQL Error 1335 (ER_SP_SUBSELECT_NYI)?

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.

What Causes This Error?

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.

How to Fix MySQL Error 1335

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

Common Causes

Scalar subquery in RETURN

Placing a subquery directly inside the RETURN clause of a stored function triggers the feature-not-implemented error.

Variable assignment using subquery expression

Using SET var = (SELECT …) or DECLARE var DEFAULT (SELECT …) is unsupported in affected MySQL versions.

Subquery in DEFAULT parameter or trigger WHEN clause

MySQL prohibits subqueries where only constants can appear, such as parameter defaults or trigger conditions.

Related Errors

MySQL Error 1242: Subquery returns more than 1 row

Happens when a scalar subquery produces multiple rows; limit or aggregate to one row.

MySQL Error 1336: ER_SP_WRONG_NO_OF_ARGS

Raised when the argument count in a routine call does not match its definition.

MySQL Error 1415: ER_NONEXISTING_PROC_REFERENCED

Occurs when a trigger references a procedure that no longer exists.

FAQs

Can I use subqueries inside MySQL functions after 8.0.22?

Yes. Many subquery restrictions were relaxed in 8.0.22 and later, allowing subqueries in RETURN and variable assignments.

Will upgrading MySQL automatically fix existing routines?

Upgrading removes the limitation, but you must re-create the routines or run ALTER FUNCTION/PROCEDURE so they compile under the new engine.

Does Galaxy help catch Error 1335?

Galaxy’s real-time linting flags unsupported subqueries while you type, letting you refactor before the code reaches production.

Is Error 1335 related to subqueries returning many rows?

No. That situation triggers Error 1242. Error 1335 occurs even with a single-row subquery if placed in an unsupported context.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo