collect data from multiple records and group the result by one or more column. It is generally used in a SELECT statement.

mysql> select category, count(*) from myposts group by category;
+------------------------------+----------+
| category                     | count(*) |
+------------------------------+----------+
|                              |      332 |
| CodeIgniter 3 Tutorial       |       68 |
| PHP Tutorial                 |      123 |
| AJAX Tutorial                |       15 |
| JavaScript Tutorial          |       20 |
| htaccess                     |        2 |
| CodeIgniter Tutorial         |        2 |
| SMS API Integration In PHP   |       12 |
| JQuery Plugin                |       12 |
| Bootstrap 4                  |       25 |
| Codeigniter 4 Tutorial       |        5 |
| JQueryUI Tutorial            |       59 |
| SEO Tutorial                 |        3 |
| JQuery Tutorial              |       67 |
| Bootstrap 3 Tutorial         |        4 |
| HTML Tutorial                |       34 |
| VPS                          |        4 |
| Java Tutorial                |       80 |
| Laravel 8 Tutorial           |       61 |
| MySQL Tutorial               |       10 |
| Vuejs Tutorial               |       21 |
| Nodejs Tutorial              |       14 |
| Ubuntu Tutorial              |       19 |
| CSS Tutorial                 |       23 |
| Laravel 8/7                  |      208 |
| Laravel 7/6 Tutorial         |       60 |
| Laravel 7 Tutorial           |       50 |
| React JS                     |       38 |
| JSP Tutorial                 |       23 |
| C Tutorial                   |       20 |
| Angular 7/8/9/10 tutorial    |       83 |
| WordPress Plugin             |        1 |
| CodeIgniter 3 Complete Guide |       15 |
| mongodb                      |        3 |
| JQuery UI                    |        1 |
| Python                       |      185 |
| TypeScript                   |      117 |
| Go Programming               |       93 |
+------------------------------+----------+
38 rows in set (0.00 sec)


You can also use some aggregate functions like COUNT, SUM, MIN, MAX, AVG, etc. on the grouped column.


aggregate_function: It specifies a function such as SUM, COUNT, MIN, MAX, or AVG etc. tables: It specifies the tables, from where you want to retrieve the records. There must be at least one table listed in the FROM clause.


WHERE conditions: It is optional. It specifies the conditions that must be fulfilled for the records to be selected.


SELECT emp_name, SUM(working_hours) AS "Total working hours"  
FROM employees  
GROUP BY emp_name;