Editorial / Best Answer
				 
							 						        Answered by: 
				       	Ankush Sharma
			                            
			         
                        
                        
			        
				 
	                    Though the HAVING clause specifies a condition that is similar to the purpose of a WHERE clause, the two clauses are not interchangeable. Listed below are some differences to help distinguish between the two:
1. The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.
for Example: if for an "Select" statement we use the "where" clause then the the result based on the "where" condition results and then we can use "group by" clause to arrange in some order, Now if we want to impose the condition on that group then we use "having" clause. 
The main reason for using WHERE clause is to select rows that are to be included in the query. For example, assume table Test.Suppose I want the names, account numbers, and balance due of all customers from California and Los Angles. Since STATE is one of the fields in the record format, I can use WHERE to select those customers.
Using the code
Code
SELECT cusnum, lstnam, init
 
FROM Test
 
WHERE state IN ('CA', 'LA')
 
 
 
CUSNUM LSTNAM INIT BALDUE
 
====== ============ ==== ========
 
938472 John G K 37.00
 
938485 Mark J A 3987.50
 
593029 Lily E D 25.00
Suppose I want the total amount due from customers by state. In that case, I would need to use the GROUP BY clause to build an aggregate query.
Code
SELECT state,SUM(baldue)
 
FROM Test
 
GROUP BY state
 
ORDER BY state
 
 
 
State Sum(Baldue)
 
===== ===========
 
CA 250.00
 
CO 58.75
 
GA 3987.50
 
MN 510.00
 
NY 589.50
 
TX 62.00
 
VT 439.00
 
WY .00
Using Having 
Code
SELECT state,SUM(baldue)
 
FROM Test
 
GROUP BY state
 
HAVING SUM(baldue) > 250
 
 
 
 
 
State Sum(Baldue)
 
===== ===========
 
GA 3987.50
 
MN 510.00
 
NY 589.50
 
VT 439.00
 
			 
          
Difference between a "where" clause and a "having" clause?
Questions by Beena answers by Beena
Editorial / Best Answer
Answered by: Ankush Sharma
Though the HAVING clause specifies a condition that is similar to the purpose of a WHERE clause, the two clauses are not interchangeable. Listed below are some differences to help distinguish between the two:
Suppose I want the total amount due from customers by state. In that case, I would need to use the GROUP BY clause to build an aggregate query. Using Having1. The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions.
for Example: if for an "Select" statement we use the "where" clause then the the result based on the "where" condition results and then we can use "group by" clause to arrange in some order, Now if we want to impose the condition on that group then we use "having" clause.
The main reason for using WHERE clause is to select rows that are to be included in the query. For example, assume table Test.Suppose I want the names, account numbers, and balance due of all customers from California and Los Angles. Since STATE is one of the fields in the record format, I can use WHERE to select those customers.
Using the code
Related Answered Questions
Related Open Questions