SQLite: GROUP BY Clause

This SQLite tutorial explains how to use the SQLite GROUP BY Clause with syntax and examples.



The SQLite GROUP BY clause is used in a SELECT statement to collect data across multiple records and group the results by one or more columns.




Parameters or Arguments:

expression1, expression2, … expression_n

The expressions that are not encapsulated within an aggregate function and must be included in the GROUP BY clause.


A function such as sum, count, min, max, or avg functions.


The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.



To demonstrate this, we need one more data to be inserted in the account table:

id salary account_no emp_id
1 30000 1000 100
2 60000 1001 101
3 40000 1002 102
4 35000 1003 103
5 35000 1004 104
6 5000 105
7 5000 106
8 30000 105

(If you notice, now there are two row’s for emp_id = 105 where carries 5000 & 30000 of salary. Check out of the GROUP BY Example)
Now the following SQLite statement, returns the grouped data of employee table and account table where grouped by name:

sum(a.salary) name
60000 arunesh
30000 chiru
35000 jaya
5000 mathu
40000 naga
35000 nithya
35000 uma