How many columns can be in the group by clause

Questions by radha11

Editorial / Best Answer


  • Member Since Jul-2008 | Jul 16th, 2008

I am sure that a group by clause can have all columns which are there in that table,not sure if you are looking for anotehr answer

Showing Answers 1 - 16 of 16 Answers


  • Aug 30th, 2008

For Aggregation:
No. of cols in group by clause = No. of cols in SELECT clause - No. of cols to be aggregated.

For eliminating the duplicates
No. of cols in group by clause = No. of cols in SELECT clause.

In general there might be n number of cols that can be used in the group by clause, which depends on
your number of cols present in SELECT clause


If we are using aggregate function in select clause then there should be one column in group by clause, Let me explain with the example.

Select max(sal),min(hire_date),ename, lastname
from emp
where lastname like '_a%'
group by ename;

So you have to use atleast one column (No aggregate funciton).


  • Feb 21st, 2010

The column names listed in select clause other than agrt function list in that select clause is must.
Other column names in that table is optional (If req you can add).

  Was this answer useful?  Yes

When you mention a column name in GROUP BY Clause you must mention the same in SELECT statement.

This is not required.

Foe eg: The below query will work.

select count(*), e.deptno
from emp e
group by e.deptno, e.sal;

  Was this answer useful?  Yes

abhinow kumar

  • Jul 20th, 2011

A group by clause can have all columns of table except those column which are used in aggregate function in select clause

  Was this answer useful?  Yes


  • Jul 21st, 2011

In GroupBy clause contains the no of columns in the select Statement to retrieve the data.

  Was this answer useful?  Yes

akshya dash

  • Jul 25th, 2011

there can be n no of columns in a group by clause other than group functions

for ex
select ename, deptno max(sal) from emp group by ename,deptno;

here max(sal) is a group function

and ename and deptno are the columns in emp table

there is one rule
the columns that are required to display that columns should be written after group by clause other than group function.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions