hello,
I have two questions regarding 'Using group functions and GROUP BY' clause
Can we use GROUP BY clause without using group functions? Technically speaking, for a GROUP BY clause to be used, a group functions must appear in the SELECT list.
Below example does not use a group function but using two columns in group by clause and executes successfully
SQL> select job_id, max_salary from jobs group by max_salary,job_id;
JOB_ID MAX_SALARY
---------- ----------
PR_REP 10500
AD_PRES 40000
MK_REP 9000
HR_REP 9000
PR
FI_ACCOUNT 9000
DBA
ST_CLERK 5000
MK_MAN 15000
HR
ST_MAN 8500
AC_ACCOUNT 9000
IT_PROG 10000
FI_MGR 16000
AC_MGR 16000
SA_REP 12000
PU_MAN 15000
PU_CLERK 5500
AD_VP 30000
AD_ASST 6000
SA_MAN 20000
SH_CLERK 5500
IT_DBA
23 rows selected.
and the below second example has no group functions but using just one column in group by clause and throws error)
SQL> select job_id, max_salary from jobs group by max_salary;
select job_id, max_salary from jobs group by max_salary
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
---------------------------------------------------------------------------------------------------------
Please explain the difference why the result is different in the second example
Thank you
Thank you