SQLite HAVING Clause

The SQLite HAVING clause is used to specify conditions that filter which group results appear in the final results. The WHERE clause places conditions on the selected columns, whereas the HAVING clause places conditions on groups created by the GROUP BY clause.

The position of HAVING clause in a SELECT query:

snippet
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY

Syntax:

snippet
SELECT column1, column2
FROM table1, table2
WHERE [ conditions ]
GROUP BY column1, column2
HAVING [ conditions ]
ORDER BY column1, column2

Example:

Let's take an example to demonstrate HAVING Clause. We have a table named "STUDENT", having the following data:

Sqlite Having clause 1

Example1:

Display all records where name count is less than 2:

snippet
SELECT * FROM STUDENT GROUP BY NAME HAVING COUNT(NAME) < 2;

Output:

Sqlite Having clause 2

Example2:

Display all records where name count is greater than 2:

snippet
SELECT * FROM STUDENT GROUP BY NAME HAVING COUNT(NAME) > 2;

Output:

Sqlite Having clause 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +