SQL HAVING Clause

SQL HAVING Clause

The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

SQL HAVING Syntax

image

SQL HAVING Example

We have the following "Orders" table:

image

Now we want to find if any of the customers have a total order of less than 2000. We use the following SQL statement:

image

Now we want to find if the customers "Kumari" or "Jensen" have a total order of more than 1500. We add an ordinary WHERE clause to the SQL statement:

image

The result-set will look like this:

image

Comments

Popular posts from this blog

XML Document Schema

Extended Relational-Algebra Operations.

Distributed Databases:Concurrency Control in Distributed Databases