Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle Group By Clause

The GROUP BY clause groups data from multiple record and returns one row for each group. On other hand, it reduces the number of rows in the result set. The GROUP BY clause must appear after the WHERE clauses.

Oracle GROUP BY CLAUSE Syntax

To group the data from multiple record into one row for each group, use the following syntax:

Syntax

Parameters:

tablename: The table name from which you want to fetch the records.

condition: To specify the conditions that must be fulfilled for the records to be selected.

GROUP BY: To sorts data set in descending order.

aggregate_function: It specifies the aggregate functions i.e. SUM, COUNT, MIN, MAX or AVG functions.

Oracle GROUP BY CLAUSE example

The following Oracle statement is used to group "firstName" from "tblCustomerLoan" table:

Example

Note:

In the above example, we have fetched records from "tblCustomerLoan" table with GROUP BY on "firstName". As you can see, the GROUP BY clause returns sum of "workHover" values.

Oracle GROUP BY CLAUSE example with COUNT function

The following Oracle statement is used to group "firstName" and count repetitive "firstName" in the column "firstName" from "tblCustomerLoan" table:

Example

Note:

In the above example, we have grouped "firstName" and count repetitive "firstName" in the column "firstName" from "tblCustomerLoan" table. As you can see, the GROUP BY clause returns count for each repetitive "firstName".

Oracle GROUP BY CLAUSE example with COUNT function & JOIN

The following Oracle statement is used to group "banks" name and count repetitive "banks" name in the column "banks" from "tblbankdemataccountcharges" table:

Example

Note:

In the above example, we have grouped "banks" name and count repetitive "banks" name in the column "banks" from "tblbankdemataccountcharges" table with INNER JOIN "tblbankheadquartersandaddress" table. As you can see, the GROUP BY clause returns count for each repetitive "banks" name.