Difference between WHERE and HAVING in SQL

CuriousKen picture CuriousKen · Jun 15, 2011 · Viewed 25.6k times · Source

Possible Duplicate:
SQL: What's the difference between HAVING and WHERE?

I have seen various discussions on WHERE and HAVING. I still have a question: is HAVING used only when considering aggregates, or can it be used in more general terms: whenever you have created or aliased a field in your query? I know that WHERE should always be used when possible.

Answer

sealz picture sealz · Jun 15, 2011

HAVING specifies a search for something used in the SELECT statement.

In other words.

HAVING applies to groups.

WHERE applies to rows.