Learn it on Mainframe Path. Do it with Mainframe KIT.Learn on Mainframe Path ▸
Mainframe KIT ● Nothing leaves this tab

-122

Column or expression in the select list is not validNEGATIVE SQLCODE · CHECKED 2026-11-07
Checked against IBM documentation

A select list mixes plain columns or expressions with grouping, but they are not all covered by GROUP BY, so Db2 rejects the statement.

QUICK ANSWER

A select list mixes plain columns or expressions with grouping, but they are not all covered by GROUP BY, so Db2 rejects the statement.

LIKELY CAUSES, IN THE ORDER OF THIS ENTRY

  1. A column selected next to SUM, COUNT, MAX or similar with no GROUP BY at all.
  2. A selected column missing from the GROUP BY list.
  3. An expression in the select list that does not exactly match a grouping expression.
  4. A HAVING clause with no GROUP BY, which counts as grouping with no columns, so no plain column may be selected.
  5. An ORDER BY sort key that mixes grouped and non-grouped data in a grouped result.

CHECKED 7 Nov 2026 IBM: Db2 13 for z/OS Codes: -122

MOST LIKELY

A column selected next to SUM, COUNT, MAX or similar with no GROUP BY at all.

FIRST CHECK

Add every plain selected column or expression to GROUP BY, written the same way as in the select list.

TRY IT ▸

Site search

What it means

When a query groups rows, or uses a column function such as SUM or COUNT, each item in the select list must produce one value per group. A plain column that is neither in GROUP BY nor inside a column function does not, so Db2 stops the statement before running it.

Typical causes

  • A column selected next to SUM, COUNT, MAX or similar with no GROUP BY at all.
  • A selected column missing from the GROUP BY list.
  • An expression in the select list that does not exactly match a grouping expression.
  • A HAVING clause with no GROUP BY, which counts as grouping with no columns, so no plain column may be selected.
  • An ORDER BY sort key that mixes grouped and non-grouped data in a grouped result.

How to fix it

  1. Add every plain selected column or expression to GROUP BY, written the same way as in the select list.
  2. Or remove the column from the select list if you do not need it per group.
  3. Or wrap the column in a column function if one value per group is what you want.
  4. Rerun the statement.

Example

Illustrative only; names and values are invented.

SQLCODE = -122, SQLSTATE 42803
-- SELECT DEPT, COUNT(*) FROM EMP   (DEPT is not grouped)