Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Group By clause and Group function

user10913793Apr 10 2019 — edited Apr 20 2019

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

This post has been answered by CarlosDLG on Apr 10 2019
Jump to Answer

Comments

Post Details

Added on Apr 10 2019
6 comments
571 views