Having clause

Having Clause in SQL Statement

Having clause is a clause of select statement responsible to retrieve record from the database with a group depending on a condition. The basic difference between where clause is meant for row restriction and having is meant for group restriction.

In this topic we will get knowledge about How having clause is used in SQL select query.

Please read the previous post
Introduction to Structured Query Language (SQL)
Object-Relational Database
SELECT Statement in SQL
Group By Clause in SQL

It enables users to filter results based on specified groups. The SQL HAVING clause is used with the GROUP BY clause. This clause can be used with aggregate functions, while the WHERE clause cannot.

Syntax :
Select <exp>
From <t_name>
[where <cond>]
[group by<col_name>]
[having<group _ cond>]


Select deptno, job, max(sal), min(sal), sum(sal),count(*) from emp
Where deptno!=30
Group by deptno,job
Having max(sal)>2000;

Select Statement Syntax

Select <exp>
From <t_name>
[having by <group col_name>]
order by <col_name>[asc|desc]];

Leave a Comment

Your email address will not be published. Required fields are marked *