Oracle: GROUP BY Clause

In Oracle GROUP BY Clause helps to group the same values present in the table to provide a concise result.

Syntax

Select Column from Table_name
GROUP BY Column;

The Column in the above syntax is the name of the column containing values that need to be summarised.

Example: How to work with GROUP BY Clause?

You have a database of Students of different sections, to know the summary of section present in the database we can use GROUP BY Clause. Refer to the Children table below:

Group by

Now, to apply Group By follow the code below:

select Section from Children 
group by Section;

OUTPUT:

Group by

Example: How to use aggregate functions with GROUP BY Clause?

Let's consider a case wherein we have Student data of different sections along with marks of Students. So to find the highest marks for every section we can use theĀ GROUP BY Clause:

Select Section, MAX(marks) from Children 
group by Section;

OUTPUT:

Group by

From the above output, we got to know the highest scoring of students from each section A, B, and C.