SQL GROUP BY – SQL Tutorial | Software Testing Material

SQL Group By:

The SQL GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

Syntax:

Example:

To fetch the total amount of salary on each Employee, then GROUP BY query would be as follows:

Here I have executed both the queries to show you the output of SAMPLETABLE and the output of SAMPLETABLE with GROUP BY statement.

SQL Group By

Now, I have modified the data in the SAMPLETABLE. I have added some duplicate records.

Again I am executing both the queries to show you the output of SAMPLETABLE and the output of SAMPLETABLE with GROUP BY statement.

How to Insert Data in the SQL Table

In the below image, we could see two queries. You could find duplicate values in the table name SAMPLETABLE. Total number of records are 4 based on GROUP BY in the second SELECT query. SELECT GROUP BY statement displays two columns (such as EmpName and SALARY) and grouped the records with the EmpName column.

SQL Group By

In the next tutorial, we will see how to use HAVING in SQL

Check out the complete SQL Tutorial by clicking on below link:

SQL Tutorial – Complete

SQL Group By

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment

Share via
Copy link
Powered by Social Snap