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

1

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.

2

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

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

3

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

HAVING clause is used with an only SELECT statement.

4

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.

5

WHERE clause is used for row operations.

Having clause is used for column operations.

6

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.

7

WHERE clause checked condition while query running. 

HAVING clause already found query result.

8

WHERE clause is used before the GROUP BY clause.

HAVING clause is used after GROUP BY clause.

9

WHERE clause used without GROUP BY clause.

Having clause not use without GROUP BY clause.

10

WHERE clause before grouping it selects rows.

HAVING clause after grouping selects rows.

11

Syntax of WHERE clause

SELECT * 
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;

12

Example of WHERE clause

SELECT 
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