Informix Error -19828: ORDER BY column or expression must be in SELECT list in this context.
Cause and resolution
ORDER BY column or expression must be in SELECT list in this context.
You cannot omit the ORDER BY column or expression from the SELECT list in the following situations:
* The UNIQUE or DISTINCT operator is used. * The UNION, INTERSECT, or MINUS operator is used. * The query selects into a temporary table (SELECT ... INTO TEMP). * A distributed query references a server and requires ORDER BY columns to be in the SELECT list is used. * The query uses the GROUP BY clause with aggregate expressions. * The expression uses an alias to a column substring.
Revise the SQL statement to follow these rules.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-19828 fires when an ORDER BY column/expression is omitted from the SELECT list in a
context that requires it — per the official guidance:
UNIQUE/DISTINCTused, per the official guidance.UNION/INTERSECT/MINUSused, per the official guidance.- The query selects into a temporary table (
SELECT ... INTO TEMP), per the official guidance. - A distributed query referencing a server requiring
ORDER BYcolumns in theSELECTlist, per the official guidance. GROUP BYused with aggregate expressions, per the official guidance.- The expression uses an alias to a column substring, per the official guidance.
Solutions / Resolution
- Add the
ORDER BYcolumn/expression to theSELECTlist, per the official guidance, in any of the listed contexts.
Examples
ORDER BY omitted from SELECT with DISTINCT
SELECT DISTINCT col1 FROM tab ORDER BY col2;
-- -19828: col2 must be in the SELECT list
Corrected
SELECT DISTINCT col1, col2 FROM tab ORDER BY col2;
Diagnostic Checks
- Check whether the query matches one of the six listed contexts, and add the missing
ORDER BYcolumn/expression to theSELECTlist.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -19828 in this set yet.
An ORDER BY column/expression is missing from the SELECT list in a context that requires
it — add it to the SELECT list.