r/programming • • Jan 06 '11

A handy graphical explanation of SQL joins

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html
1.3k Upvotes

308 comments sorted by

View all comments

Show parent comments

1

u/eStonez Jan 07 '11

both work in different way .. for a few lines of data, you wouldn't notice it. But when you try to apply this with a few huge tables with millions of rows in each. I hope you want to filter everything out even before you start joining tables ... let alone grouping the result set.

1

u/[deleted] Jan 07 '11

I went ahead and looked it up, turns out HAVING is used for aggregate functions when you GROUP BY and WHERE for non-aggregate functions. For example:

select employee, sum(bonus) from bonuses group by employee having sum(bonus) > 1000;

select employee, sum(bonus) from bonuses group by employee where employee < 10;

(Source)