Group By clause in MYSQL by R4R Team

MySQL GROUP BY Clause
-The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one or more column.
-It is generally used in a SELECT statement.

Syntax: SELECT columns
FROM table_name
GROUP BY column;

SELECT * FROM employee;

emp_id emp_name department emp_salary
1 Aman D1 34000
2 Ram D2 43000
3 Ramesh D1 20000
4 John D3 65000
5 Sita D1 10000
6 Dinesh D2 15000

Now Make Group according to the department and count employee in each department:

SELECT department,COUNT(*) FROM employee GROUP BY department;

department COUNT(*)
D1 3
D2 2
D3 1




Leave a Comment: