You can group the SELECT query results, based on one or several columns using the GROUP BY SQL operator. After the GROUP BY operator, you specify the column name that possibly contains duplicate names. Performing grouping, you will have just one record for every value in the specified column. Typically you may use some SQL aggregate functions to display in other column(s) sum, max, min, or count for the grouped records.
In the SELECT statement, GROUP BY clause follows the WHERE condition and precedes the ORDER BY clause.
Assume we have awards table storing the data on FIFA Golden Ball award winners, and we want to count the awards for each player in the table:
We want to count the number of awards for each player, and will use grouping for this purpose. In SQL, grouping can be done in the following form:
SELECT player, COUNT(player) FROM awards GROUP BY player;
which is equivalent to the following QueryDSL:
The result will be: