The group by clause is used for grouping the records of the database table according to our need. Which is an optional part of SELECT statement.
SELECT column1, column2
WHERE [ conditions ] GROUP BY column1, column2
ORDER BY column1, column2
The GROUP BY clause must appear after the FROM and WHERE clauses
Example of Group by in a Statement. Consider following Employee table
Example of Group by in a Statement with WHERE clause
NOTE: Group By clause will always come at the end, just like the Order by clause.
The HAVING clause must follow the GROUP BY clause in a query and must also precede the ORDER BY clause if used.
select column_name, function(column_name)
WHERE column_name condition
GROUP BY column_name
HAVING function(column_name) condition
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.