1987
MySQLERRORNotableQueryHIGH confidence
Operand should contain N column(s)
Production Risk
Low — query is rejected; no data is modified.
What this means
A subquery or row value constructor returns a different number of columns than expected by the outer query context. For example, comparing a single column to a subquery that returns two columns.
Why it happens
- 1Subquery in WHERE clause returns more columns than the comparison expression expects.
- 2Row constructor (a, b) = (subquery) where subquery returns wrong column count.
- 3IN clause subquery returns multiple columns when only one is expected.
How to reproduce
trigger — this will error
trigger — this will error
SELECT * FROM t1 WHERE col1 = (SELECT col1, col2 FROM t2 LIMIT 1);
expected output
ERROR 1987 (21000): Operand should contain 1 column(s).
Fix 1
Reduce the subquery to the correct number of columns
Reduce the subquery to the correct number of columns
SELECT * FROM t1 WHERE col1 = (SELECT col1 FROM t2 LIMIT 1);
Why this works
Align the subquery output columns with the comparison context.
Fix 2
Use a row constructor if multiple columns are intended
Use a row constructor if multiple columns are intended
SELECT * FROM t1 WHERE (col1, col2) = (SELECT col1, col2 FROM t2 LIMIT 1);
Why this works
Row value constructors allow multi-column comparisons.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1987 ER_OPERAND_COLUMNS
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev