Javatpoint Logo

91-9990449935

 0120-4256464

PostgreSQL Having Clause

In PostgreSQL, HAVING clause is used in combination with GROUP BY clause to pick out particular rows where the function's result meets some condition.

Syntax:

See this example:

Let's take a table "EMPLOYEES" having the following data.

 HavingClause

See this example, which would display record for which name count is less than 2.

Execute the following query:

Output:

 HavingClause

Example2:

Let's insert some duplicate records in the "EMPLOYEES" table. Add the following data:

 HavingClause

Output:

 HavingClause

Execute the following query to retrieve the name from table "EMPLOYEES" where name count is greater than 1.

Output:

 HavingClause