What is the difference between HAVING and WHERE in SQL

0 votes
I want to know the difference between HAVING and WHERE in an SQL SELECT statement
Feb 17, 2022 in Database by Vaani
• 7,020 points
574 views

1 answer to this question.

0 votes

HAVING: It is used to check after the aggregation occurs
WHERE: It is used to check before the aggregation occurs.

For Example:

select State, CNT=Count(1)
From Address
Where Country = 'IND'
Group By State
Results in a table of all States in IND and the number of addresses in each State.

Code:

select State, CNT=Count(1)
From Address
Where Country = 'IND'
Group By State
Having Count(1)>5

Results in a table of States in MA with more than 5 addresses and the number of addresses in each State

If you need to know more about SQL, it is recommended to go for the SQL Certification today.

answered Feb 17, 2022 by Vaani
• 7,020 points

Related Questions In Database

0 votes
0 answers

What is the difference between drop table and delete table in SQL Server?

What is the distinction between the following ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,010 points
557 views
0 votes
1 answer

Can you explain what is the difference between UNION and Join?

Hi Sahana,  I got your doubt, Checkout these ...READ MORE

answered May 30, 2019 in Database by sampriti
• 1,120 points
1,134 views
0 votes
1 answer

What is the rule to use group by, having and where clause?

Hi samar, this is a very common mistake ...READ MORE

answered Jul 2, 2019 in Database by anonymous
1,073 views
0 votes
0 answers

What's the difference between a temp table and table variable in SQL Server?

We can build temp tables in SQL ...READ MORE

Feb 25, 2022 in Database by Vaani
• 7,020 points
441 views
0 votes
1 answer

Insert date value in SQL table

Always use ANSI default string literal format for date i.e. YYYY-MM-DD like below. INSERT ...READ MORE

answered Feb 17, 2022 in Database by Neha
• 9,060 points
163,284 views
0 votes
0 answers

Left Join With Where Clause

I need to take all of the ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,010 points
423 views
0 votes
1 answer

SQL JOIN - WHERE clause vs. ON clause

They are not the same thing. Consider these ...READ MORE

answered Sep 16, 2022 in Database by narikkadan
• 63,420 points
570 views
0 votes
1 answer

Which query to use for better performance, join in SQL or using Dataset API?

DataFrames and SparkSQL performed almost about the ...READ MORE

answered Apr 19, 2018 in Apache Spark by kurt_cobain
• 9,390 points
1,528 views
0 votes
1 answer

What is the difference between SQL, PL-SQL and T-SQL?

SQL SQL is the standard language for relational ...READ MORE

answered Feb 16, 2022 in Database by Vaani
• 7,020 points
655 views
0 votes
1 answer

What is an index in SQL?

An index is used to speed up ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,020 points
425 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP