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 in Database by Vaani
• 7,020 points
122 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

answered Feb 17 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 in Database by Kithuzzz
• 20,660 points
181 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
709 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
689 views
0 votes
0 answers
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 in Database by Neha
• 8,940 points
33,723 views
0 votes
0 answers

Left Join With Where Clause

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

Aug 14 in Database by Kithuzzz
• 20,660 points
49 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 in Database by narikkadan
• 37,660 points
78 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,048 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 in Database by Vaani
• 7,020 points
190 views
0 votes
1 answer

What is an index in SQL?

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

answered Feb 3 in Database by Vaani
• 7,020 points
115 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