Informix Error -251
-251 ORDER BY or GROUP BY column number is too big.
The ORDER BY or GROUP BY clause uses column-sequence numbers, and at least one of them is larger than the count of columns in the select list. Check that you entered the clause correctly and that you did not omit an item from the select list.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-251 means an ORDER BY or GROUP BY clause used a column-sequence number larger than the
actual number of columns in the select list.
- A typo in the column number.
- The select list was edited (a column removed) without updating a corresponding
ORDER BY/GROUP BYcolumn-number reference that pointed at it or beyond it. - Miscounting column positions, especially in a select list containing expressions or aliases that make visual counting less obvious than with plain column names.
- Confusion between positional numbering and an intended column name — using a number when a name was actually meant.
Solutions / Resolution
- Check the
ORDER BY/GROUP BYclause against the actual select list, per the official guidance, and confirm no item was omitted from the select list. - Correct the column number if the select list changed since the clause was written.
- Consider using explicit column names or aliases in
ORDER BY/GROUP BYinstead of positional numbers — this avoids the entire class of fragility where a later select-list edit silently breaks a positional reference.
Examples
The straightforward case
SELECT customer_id, name, region FROM customer ORDER BY 5;
-- -251: only 3 columns in the select list, but ORDER BY references
-- column 5
Fix:
SELECT customer_id, name, region FROM customer ORDER BY 3;
-- or, more robustly:
SELECT customer_id, name, region FROM customer ORDER BY region;
A select list edit breaking a positional reference
-- Originally:
SELECT id, name, email, phone FROM customer ORDER BY 4; -- phone
-- After removing a column during a later edit:
SELECT id, name, email FROM customer ORDER BY 4;
-- -251: phone is gone, and only 3 columns remain
Using ORDER BY email (or whatever the actual intended column is) instead of a positional number
avoids this fragility entirely.
Diagnostic Checks
- Count the columns in the select list and compare against the number referenced in
ORDER BY/GROUP BY. - Review recent edits to the select list if this appeared unexpectedly on a query that used to work.
Related Errors / Related Topics
- -201 — "A syntax error has occurred." The general SQL-parsing-error family this fits into.
Prefer explicit column names over positional numbers in ORDER BY/GROUP BY — it's the best
prevention against this error recurring after future select-list edits.