Sunday, 24 November 2013

Using where clause with group by

Bismillahir Rahmanir Raheem

Consider the table student where  I have three columns

select dept,count(student)
from   student
where gender='M'
group by dept
having count(student) >= 2;

In the above query I have used where before group by what it does is ,it ignores those rows from the
consideration of group by clause which does not satisfy the where condition.

So group by only makes group that satisfy the condition , this gives you a way to filter your group before they are made and by using having clause with group by we can filter goups after they have been made.

No comments:

Post a Comment