Grokking SQL for Tech Interviews
Ask Author
Back to course home

0% completed

GROUP BY
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

GROUP BY

In MySQL, the GROUP BY clause is used to group rows that have the same values in specified columns. This is often used in conjunction with aggregate functions, such as COUNT, SUM, AVG, MAX, or MIN, to perform calculations on each group of rows.

Syntax

SELECT column1, column2, FROM table_name WHERE condition GROUP BY column1, column2;

Example

Suppose we have a Students table as shown below:

Now, suppose you want to find out how many students are enrolled in each subject. In order to do this, we formulate the following query:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible