-122   COLUMN OR EXPRESSION IN THE SELECT LIST IS NOT VALID

Explanation

The SELECT statement contains one of these errors:

  • The statement contains a column name and an aggregate function in the SELECT clause, but no GROUP BY clause.
  • A column name is contained in the SELECT clause (possibly within a scalar function) but not in the GROUP BY clause. Grouping expressions can be used in a SELECT list. A grouping expression specifies only one value for each group. A grouping expression that is specified in this context must exactly match a grouping expression that is specified in the GROUP BY clause, except that blanks are not significant.
    Attention: A HAVING clause specified without a GROUP BY clause implies a GROUP BY with no columns. Thus, no column names are allowed in the SELECT clause.
  • An expression is specified in the SELECT clause but not in the GROUP BY clause.
  • A sort-key-expression was specified in the ORDER BY clause, the result table contains grouped data, but the select-clause and ORDER BY clause contain a mixture of grouped data and non-grouped data. Grouping expressions can be used in a sort-key-expression of an ORDER BY clause. A grouping expression specifies only one value for each group. A grouping expression that is specified in this context must exactly match a grouping expression that is specified in the GROUP BY clause, except that blanks are not significant.

System action

The statement cannot be processed.

Programmer response

You can correct the statement by:

  • Including the columns or expressions in the GROUP BY clause that are in the SELECT clause, or
  • Removing the columns or expressions from the SELECT clause.

SQLSTATE

42803