Computer >> Computer tutorials >  >> Programming >> MySQL

What is the significance of using multiple columns in MySQL GROUP BY clause?


By specifying multiple columns in GROUP BY clause we can split the result set into smaller groups. The more columns specified in GROUP BY clause, the smaller the groups will be.

Example

mysql> Select designation, YEAR(Doj), count(*) from employees GROUP BY designation, YEAR(DoJ);

+-------------+-----------+----------+
| designation | YEAR(Doj) | count(*) |
+-------------+-----------+----------+
| Asso.Prof   | 2013      | 1        |
| Asst.Prof   | 2015      | 1        |
| Asst.Prof   | 2016      | 1        |
| Prof        | 2009      | 2        |
| Prof        | 2010      | 1        |
+-------------+-----------+----------+

5 rows in set (0.00 sec)