Filter Data Using the Having Clause

The reason for having a database is to have vast amounts of data organized and readily available. SQL is the means by which we can communicate with the database and tell it to find exactly what we need. From thousands of records, we can filter it down to precisely what we are searching for, granted if the database schema was created efficiently.

Let’s look at an example, using the HAVING clause. Let’s say we wanted to search for all employees who have an average salary of $50,000.

*Note, when using HAVING you always have to incorporate GROUP BY filtering.

Here’s how we would do it.

SELECT employee, AVG(salary)
FROM employee_data
GROUP BY employee
HAVING AVG(salary) > 50000;

See how used the AVG aggragate function to get the average salaray?

You can also find this information using the WHERE clause.

Bookmark it and Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • BlinkList
  • Bumpzee
  • De.lirio.us
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
Update,Change, Delete Data QueryInserting Data into SQL TablesHow to Concantenate Strings

4 Comments so far

  1. jyot on October 22nd, 2008

    this is good example

  2. andrew on March 5th, 2009

    Thanks, very helpful

  3. Paid Surveys on May 28th, 2009

    Hi I’m interested in advertising with this site, Is your content wholly related to Dr. Laura?

  4. Paid Surveys on May 28th, 2009

    Hi I’m interested in advertising with this site, Is your content wholly related to Dr. Laura?

Leave a reply