Informix Error -23923: HAVING clause should be accompanied by a GROUP clause or with aggregates on all columns in the SELECT clause.
Cause and resolution
HAVING clause should be accompanied by a GROUP clause or with aggregates on all columns in the SELECT clause.
The HAVING clause in a query should be accompanied by a GROUP BY clause or by a SELECT clause containing only AGGREGATES on columns or column-expressions. The HAVING clause is used to apply filter expressions on a "grouped" result. A grouped result is obtained either by using a GROUP BY clause or by using only AGGREGATES in the SELECT clause. In the latter case, the result involves only one group and the result contains only one aggregated row.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-23923 fires when a HAVING clause is used without a GROUP BY clause or a SELECT
list consisting entirely of aggregates — per the official guidance, HAVING filters a
grouped result, and a grouped result comes either from GROUP BY or an all-aggregate
SELECT list (which produces a single aggregated group/row).
HAVINGused withoutGROUP BY, on aSELECTlist that isn't entirely aggregates, per the official guidance — the direct, only cause.
Solutions / Resolution
- Add a
GROUP BYclause, per the official guidance, or - Use only aggregates in the
SELECTclause, per the official guidance.
Examples
HAVING without a grouped result
SELECT order_id, total FROM orders HAVING total > 100;
Corrected
SELECT customer_id, SUM(total) FROM orders GROUP BY customer_id HAVING SUM(total) > 100;
Diagnostic Checks
- Check the query for a
GROUP BYclause or an all-aggregateSELECTlist, and add whichever is missing.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -23923 in this set yet.
A HAVING clause was used without a grouped result — add GROUP BY or use only
aggregates in the SELECT clause.