MySQL Group By

Group By clause is used to group the result set by one or more column.

Suppose we have students table as follows -

students table

When we count number of students, we will get this output -

SELECT COUNT(*) FROM students;
count

But what if we want to get the students count based on their age. For this we are using GROUP BY clause. The statement is as follows -

SELECT age, count(*) FROM students GROUP BY age;
count



Read more articles


General Knowledge



Learn Popular Language