From: amonotod <[EMAIL PROTECTED]>
> > From: amonotod <[EMAIL PROTECTED]>
> > > From: Hernan Arredondo <[EMAIL PROTECTED]>
> > > Date: 2005/01/24 Mon PM 12:41:56 CST
> 
> > FROM THE DOCS!
> > <snip>
> >     One alternative method to get a row count for a SELECT is to 
> > execute a ``SELECT COUNT(*) FROM ...'' SQL statement with the same
> > ``...'' as your query and then fetch the row count from that.
> > </snip>
> 
>   I guess I should have pointed out that the part you really need to
>   take notice of was the last paragraph, in which it is suggested that
>   you run a "select count()" before you run your real query.  
> 
>  One extra piece of advice, it says "select count(*)", but I suggest
>  you use just "select count(<first_column>)" instead.  

Maybe this depends on the database server, but I do believe count(*) 
will be quicker than COUNT(<first_column>) under e.g. MS SQL. Besides 
the two do not have to return the same number. COUNT(<forst_column>) 
doesn't count the rows in which the first_column is null. Eg this 
query returns
        5, 4, 3

select count(*), count(foo), count(distinct foo)
from (
        select 1 as Foo
        union all
        select 2
        union all
        select 1
        union all
        select 3
        union all
        select null
) as Tbl


If you want the count of rows, use COUNT(*), if you want the count of 
Foos use Count(Foo).

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

Reply via email to