1339
MySQLerrorqueryhigh confidence

Case not found for CASE statement (SQL expression)

Production Risk

Low — query fails; no data is changed.

What this means

A CASE expression used in a query found no matching WHEN and no ELSE was provided.

Why it happens
  1. 1CASE expression with no matching WHEN clause and no ELSE
  2. 2NULL input value with no explicit WHEN NULL handling
How to reproduce
trigger — this will error
trigger — this will error
SELECT CASE 5 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END;

expected output

ERROR 1339 (20000): Case not found for CASE statement

Fix

Add ELSE to CASE expression

Add ELSE to CASE expression
SELECT CASE 5 WHEN 1 THEN 'one' ELSE 'other' END;

Why this works

Provides a fallback value for unmatched cases.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1339 ER_CASE_NOT_FOUND

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors