SQL GROUP BY

SQL GROUP BY used to get the aggregated results based on certain columns.

Syntax:

SELECT Column1, MAX(Column2)
GROUP BY Column1

The above SQL will return maximum value for each of the values from Column1.

Table: Sales

Following SQL will get the sum of sales figures from the above table.

SELECT StoreName, SUM(Sales)
FROM Sales
GROUP BY StoreName

Following will be the output:

Table:Result Set

39 views

Return to top