tech on the net

Oracle/PLSQL: ORA-00937 Error

Error Message

ORA-00937: not a single-group group function

Cause of Error

You tried to execute an SQL SELECT statement that included a GROUP BY function (ie: SQL MIN Function, SQL MAX Function, SQL SUM Function, SQL COUNT Function), but was missing the SQL GROUP BY clause.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

Rewrite the SELECT statement so that the column or expression listed in the SELECT list is also found in the GROUP BY clause.

Option #2

Remove the GROUP BY function (ie: SQL MIN Function, SQL MAX Function, SQL SUM Function, SQL COUNT Function) from the SELECT statement.

Option #3

Remove the expression from the SELECT list that was not in the GROUP BY clause.

For example, if you had tried to execute the following SELECT statement:

SELECT department, MIN(salary) as "Lowest salary"
FROM employees;

You would receive the following error message:

Oracle PLSQL

You could correct this by including department in the GROUP BY clause as follows:

SELECT department, MIN(salary) as "Lowest salary"
FROM employees
GROUP BY department;