Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: HAVING and WHERE clause
A copy of this was sent to suisum_at_ecn.ab.ca ()
(if that email address didn't require changing)
On 5 Jan 99 20:56:37 GMT, you wrote:
>I read this question from somewhere. I am confused as I think the
>correct answer should be 2. But the correct answer is 1.
>
>Which clause would you use to exclude rows from a group calculation?
>
>1. WHERE
>2. HAVING
>3. ORDER BY
>4. INTO
>
>Will HAVING is for a group of rows and WHERE is for one row?
where will remove a row from a group calculation (where is processed BEFORE aggregates). You would use the where clause to exclude a row from being part of a group calculation.
having will remove an already grouped result row (having is processed AFTER the aggregate).
Its a misleading question -- a trick question if you will. HAVING is for processing the results of group calculations, eg: "select dept, count(*) from emp group by dept having count(*) > 3" to find all depts with more then 3 emps. Your eye is drawn toward the "exclude .. group calculation" and that leads you to the HAVING clause...
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA
--
http://govt.us.oracle.com/ -- downloadable utilities
Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Tue Jan 05 1999 - 20:18:41 CST
![]() |
![]() |