HAVING is a SQLite clause that is used to specify conditions for SQLite grouping. SQLite HAVING syntax requires the use of SQLite aggregate functions. SQLite HAVING example uses include filtering SQLite GROUP BY results. SQLite HAVING can be used in conjunction with SQLite select.
SELECT column1, column2, COUNT(*) FROM table_name GROUP BY column1, column2 HAVING condition;
In the SQLite HAVING example below, the city column is filtered to display only values greater than 1.
SELECT city, COUNT(*) FROM customers GROUP BY city HAVING COUNT(city) > 1;
SQLite Having and Group By
The SQLite GROUP BY clause is used to group SQLite data by one or more columns. SQLite HAVING clause is used in conjunction with the SQLite GROUP BY clause to filter groups based on a specified condition.
For example, the following SQLite statement would group customers by city and then only return cities that start with San:
SELECT city, COUNT(*) FROM customers GROUP BY city HAVING city LIKE 'San%';