WHERE and HAVING clause

Hello and welcome everyone. In this article, we will learn about the difference between Where and Having clause. Let’s go. Primary Key and Foreign Key

WHERE and HAVING clause

MongoDB with .Net Core course link => MongoDB

C# basic course click on: C Sharp

Web API 2- .Net Core In depth In 5 Hours click on: Web API 2


WHERE clause is used to get a specific result with a specific condition and also it filters records.

HAVING clause is used with the GROUP BY clause to filter group values.


WHERE clauses is not used aggregated data, it used with row?s data.

HAVING clauser used aggregated data for filter values from the group.


WHERE clause is used with SELECT statement, UPDATE statement and DELETE statement.

HAVING clause is used with an only SELECT statement.


WHERE clause has built-in operation and indexes are set, so filter result comes fast.

HAVING clause firstly filter query and after that, it saved, gathered and after that sorted results, so it?s slow than WHERE clause.


WHERE clause is used for row operations.

Having clause is used for column operations.


WHERE clause aggregate functions not use because this function only performed on columns,

Having clause is used for column operations; therefore we can use aggregate functions.


WHERE clause checked condition while query running. 

HAVING clause already found query result.


WHERE clause is used before the GROUP BY clause.

HAVING clause is used after GROUP BY clause.


WHERE clause used without GROUP BY clause.

Having clause not use without GROUP BY clause.


WHERE clause before grouping it selects rows.

HAVING clause after grouping selects rows.


Syntax of WHERE clause

FROM table_name 
WHERE condition;

Syntax of HAVING clause

SELECT column_name_1, column_name_2, aggregate_function
	FROM table_name
	WHERE condition
	GROUP BY column_name
	HAVING condition
	ORDER BY column_name;


Example of WHERE clause

e_id, e_name
WHERE Age > 20;

Example of HAVING clause

SELECT e_firstname as Fname, e_lastname as Lname
	FROM employee
	GROUP BY e_sex
	HAVING e_age > 25;

In this article, we learned the difference between WHERE clause and HAVING clause with their syntax and example.

Visit Our Website : https://expertwithsagarjaybhay.com/

sagar jaybhay

One thought on “WHERE and HAVING clause

Leave a Reply

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

Back to top