 Hello everybody in this lesson we're going to take a look at the difference between having and where. Now the last lesson we looked at group by and order by. The most obvious thing to do would be to come right here and say where and we're going to say this column which is actually named this will say where the average age let's say is greater than 40 which would only be the males. So let's go ahead and run this and as you can see we're not getting any output. Let's bring this up and take a look at the error it says invalid use of the group by function. What's actually happening is something to do with this group by gender right here when we're selecting gender and then we're performing an aggregate function this occurs only after the group by actually groups those rows together. So when we're trying to filter based off of this column right here of average age it really hasn't been created yet because this group by hasn't happened that's where the having clause comes into play. So let's go ahead and what we're going to do is we're going to get rid of this we're going to come right down here and instead of where we're going to say having. Now having was specifically created for this exact example it comes right after group by and after group by we can filter based off of these aggregate functions. So now if we run this we're going to get an output that only has where the average age is greater than 40. Now let's take a look at just one more example and I'm going to show you how you can use both and one query. So instead of demographics let's look at the salary table and let's run it. Now in this salary table we have this occupation and remember we have this office manager that happens twice and this is going to be our main example. So we're going to say occupation and then we'll say the average salary. Now we'll need to come down here and we'll say group by now we're going to say occupation. So this should look pretty similar because right here we have our office manager and one of the office managers made 50 one of the office managers made 60 so the average is 55,000. Now I can use the where by saying where then I'll say occupation like and let's see people who are managers. So I'll say percent manager percent and close that quote but they're like a manager and then I want to see where a manager makes more than let's say 75,000. So I won't actually say where I'm gonna say having an average salary and I need to add a space there having an average salary greater than let's say 75,000 and let's run this. So now I filtered at the row level right here in the where clause but then down here I filtered at the aggregate function level. This having is only going to work for aggregated functions after the group by actually runs. So that is the difference between the having clause and the where clause. The where clause you're most likely going to use a lot more but if you do want to filter on those aggregated function columns you have to use the having clause. I hope that that was really helpful and in the next lesson we're looking at our very last lesson in our beginner series we're going to look at limit and aliasing.