MySQL GroupBY

  • MySQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups.
  • The GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.

Syntax:

The GROUP BY clause must follow the conditions in the WHERE clause and must proceed the ORDER BY clause if one is used.

SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2;

EX:

select name, sum(salary) from customers group by name;