SQL Group By

What is GROUP BY clause in SQL?

The SQL GROUP BY clause is used when you want to groups rows that have the same values into unique group of rows. It help us to arrange identical data into groups.

The GROUP BY clause is often used with aggregate functions such as COUNT, MAX, MIN, SUM, AVG to group the rows by one or more columns.

Syntax of GROUP BY clause

Following is the syntax of GROUP BY clause, it gives you an idea about, how you can use while writing a SQL query.

 SELECT AGGREGATE_FUNCTION(column_name_1), column_name_2 FROM table_name
GROUP BY column_name_2;

Examples of GROUP BY clause

For following examples used student table, below is the data from student table.

1) GROUP BY: The count of each student roll no, student name wise.

Previous Post Next Post

Contact Form