What is the difference between HAVING and WHERE in MySQL Query?

I have a view ( viewX) based on joins of some tables:

When I use WHERE, the request is delayed, CPU usage goes up to 50%, and finally I need to close the service mysqld.exeand restart to try to solve the problem again.

When I use HAVING, the query runs fine and fast, I get the results and you're done.

The request is similar to this:

SELECT * FROM viewX WHERE column_of_view = 'foo'

SELECT * FROM viewX HAVING column_of_view = 'foo'

What's happening?

The solution I found is to do something like this:

SELECT * FROM (SELECT * FROM viewX) as T WHERE column_of_view = 'foo'

SELECT * FROM (SELECT * FROM viewX) as T HAVING column_of_view = 'foo'

GENERAL ISSUES WORK TRUE, BUT, I think this is BAD! (SELECT * FROM (... viewX) ????)

+5
source share
4

, sum, avg , select statement.where : sum (mark) > 300//

+1

- . ( )?

0

WHERE ALIAS

HAVING filters the lines after listing all the possible lines, so ALIAS names are generated

When filtering strings inside a string, a problem should occur.

0
source

All Articles