1241
MySQLERRORNotableQuery / SubqueryHIGH confidence

Operand should contain the expected number of columns

Production Risk

Low — query is rejected; fix the subquery.

What this means

ER_OPERAND_COLUMNS (1241, SQLSTATE 21000) is raised when a subquery returns a different number of columns than expected by the context. For example, a scalar subquery (used in a comparison or SELECT list) must return exactly one column.

Why it happens
  1. 1A subquery in a comparison returns more than one column
  2. 2Using a multi-column subquery where a single-column result is required
  3. 3Row constructor comparison column count mismatch
How to reproduce
trigger — this will error
trigger — this will error
SELECT * FROM orders WHERE (customer_id, amount) = (SELECT id FROM customers WHERE name = 'Alice');
-- Subquery returns 1 column, but row constructor has 2

expected output

ERROR 1241 (21000): Operand should contain 2 column(s)

Fix

Match the subquery column count to the row constructor

Match the subquery column count to the row constructor
SELECT * FROM orders WHERE (customer_id, amount) =
  (SELECT id, credit_limit FROM customers WHERE name = 'Alice');

Why this works

The subquery must return the same number of columns as the row constructor or comparison context expects.

Sources
Official documentation ↗

MySQL 8.0 — 1241 ER_OPERAND_COLUMNS

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

← All MySQL errors