using where vs having in mysql select ?

Discussion in 'MySQL' started by olddocks, Jun 28, 2007.

  1. #1
    whats the difference using where and having clause in mysql select?

    i can understand this. Can anybody help?
     
    olddocks, Jun 28, 2007 IP
  2. Clark Kent

    Clark Kent Guest

    Messages:
    122
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Let me give an example.
    you want to find customers telephone numbers who bought more than 2 products and their name is john.

    select phone, count(*) from sales where name='John' group by name having count(*)>2

    having works like after your query executes. First you filter your table with the customers John. Than you group customername to find how many sales you made. And with using "having" you filtering the result set.
     
    Clark Kent, Jun 28, 2007 IP