Difference between WHERE clause and HAVING clause in MySQL
Hello and
welcome everyone. In this article, we will learn about the difference between Where
clause and Having clause. Let’s go.
WHERE
clause and HAVING clause
MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/
C# basic course click on: https://www.udemy.com/learn-csharp-with-sagar-jaybhay/
Web API 2- .Net Core In depth In 5 Hours
click on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/
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 clause is not used
aggregated data, it used with row’s data.
HAVING
clause 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
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;
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.
Comments
Post a Comment