Stay informed about any major changes. Click here to subscribe
Filtering rows with WHERE and HAVING statements
WHERE and HAVING statements helps you place a query or an advanced filter
to identify the specific records you want to work with. For example, instead
of viewing all the rows in the Customers table, you can view just customers
from Europe. To do this, you specify criteria that limits the results
to records whose Region field is "Europe". The expression in
this example would be "Europe". You can use more complicated
expressions, however, such as "Between 1000 And 5000".
WHERE Statement
In SQL, search conditions appear in the WHERE clause of the statement,
or if you are creating an aggregate query, in the HAVING clause. When
the query runs, the database engine examines and applies the search condition
to each row in the tables you are searching. If the row meets the condition,
it is included in the query. For example, a search condition that would
find all the employees in a particular region might be: region = 'UK'
HAVING Statement
The HAVING clause is typically used in conjunction with the GROUP BY
clause, although it can be specified without GROUP BY. For example, the
SQL statement with the HAVING clause might look like this: