Having and Where - Mysql Query
Jul 5th, 2008 by sherlock Hit :: 590
“Having” clause is like “Where” clause, but it use when the query need to refer to aggregate functions, which the “WHERE” clause cannot.
SELECT user, MAX(salary) FROM users GROUP BY user HAVING MAX(salary);
Don’t use HAVING for items that should be in the WHERE clause.
For example, do not write this:
SELECT col_name FROM tbl_name HAVING col_name > 0;
Write this instead:
SELECT col_name FROM tbl_name WHERE col_name > 0;