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 -
baseurl.'/images/students.jpg'; ?> alt="students table">When we count number of students, we will get this output -
SELECT COUNT(*) FROM students;
baseurl.'/images/selectcount.jpg'; ?> alt="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;
baseurl.'/images/groupby.jpg'; ?> alt="count">