Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Why ORACLE apply "rowcount" before "distinct"?
Hi,
try to use subquery for example
select my_count
from
(select COUNT(DISTINCT(DOC_KEY)) "my_count"
FROM
FOLDER_DOC
WHERE
FOLDER_KEY = '332' or
FOLDER_KEY = '333' or
FOLDER_KEY = '334' or
FOLDER_KEY = '335'
)
where rowcount < 6000
Hope that helps
<pavel1704_at_my-deja.com> wrote in message news:83t316$ark$1_at_nnrp1.deja.com...
> I have a query , that contain condition on maximum "rownum" , and also
> DISTINCT clause...
>
> SELECT
> COUNT(DISTINCT(DOC_KEY))
> FROM
> FOLDER_DOC
> WHERE
> ROWNUM < 6000 AND
> (
> FOLDER_KEY = '332' or
> FOLDER_KEY = '333' or
> FOLDER_KEY = '334' or
> FOLDER_KEY = '335'
> )
>
> The problem is , that ORACLE always , first apply "ROWNUM" restriction,
> and
> after that on remained dataset, apply "DISTINCT" condition. So if
> original
> ( without DISTINCT and ROWNUM ) could bring 10000 records, among which
> 7000
> are distinct, factually this query bring 5000 , because ORACLE first of
> all
> take 6000 first records , and ON THEM apply "DISTINCT" ,and it can
> result in
Received on Thu Dec 23 1999 - 06:38:46 CST