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
• 5,040 points
31 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
• 5,040 points

Related Questions In Database

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
622 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
590 views
0 votes
0 answers
0 votes
1 answer

Difference between single and double quotes in SQL

Single quotes are used to indicate the ...READ MORE

answered Sep 11, 2018 in Database by CodingByHeart77
• 3,720 points
13,140 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 in Database by Neha
• 6,260 points
41 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
929 views
0 votes
1 answer

How to connect Java program to the MySQL database?

You can connect your Java code with ...READ MORE

answered May 11, 2018 in Java by Parth
• 4,630 points
850 views
0 votes
1 answer
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
• 5,040 points
60 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
• 5,040 points
29 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP