Saturday, November 1, 2014

Having and where clause sql server

Having and where clause  are similar ,but  HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause. whereas the WHERE clause applies to individual rows. A query can contain both a WHERE clause and a HAVING clause. So  When  you have used group by clause and filter  the records you should have used the the having clause otherwise used where clause

for ie
suppose we have table employee and follwing  columns
EmployeeId
JoinDate
IsActive
 so the query count the employee to join date
 select count(employeeId) group by  JoinDate having isActive=1


No comments:

Post a Comment

http://blogsiteslist.com