Re: counting records in select query

From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 02/01/05


Date: Mon, 31 Jan 2005 18:24:35 -0800

Yes, but the count might not be particularly accurate and it will hurt
performance.
You can execute a SELECT COUNT(*) with the appropriate WHERE clause to
return a count of the rows that qualify for the rowset. However, this takes
almost the same amount of time (especially for complex queries) to run the
query. This means it will cost nearly twice as much as executing the query
without counting the rows first. In addition, since the number of member
rows could change from the time you count to the time you query, the count
could be off--way off. For simple queries counting is fine--but it just
hurts scalability.

hth

-- 
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Konrad" <konrad007@poczta.onet.pl> wrote in message 
news:OtftJu2BFHA.2016@TK2MSFTNGP15.phx.gbl...
> Iterate through all records isn't big problem in my case
> because number of records returned is about to 1000.
> And as I see it takes lower than 1 sec.
> But I'am using SQL Server over internet and sending
> this records is bigger problem. So I want to know
> how many records is to send and does this operation should
> be completed or not.
> Do you know how count number of records to send
> having select query?
>
> Best regards
> Konrad
>
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:e6UA0ewBFHA.2428@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> This not a good practice. Counting records has to iterate through all
>> records on server and you'll probably have to run one select for counting
>> and the other for returning the actual records.
>> Why don't you simply limit the select with TOP (or similar) clause?
>>
>> -- 
>> Miha Markic [MVP C#] - RightHand .NET consulting & development
>> SLODUG - Slovene Developer Users Group
>> www.rthand.com
>>
>> "Konrad" <konrad007@poczta.onet.pl> wrote in message
>> news:OCshCLwBFHA.2196@TK2MSFTNGP14.phx.gbl...
>> > Hi
>> >
>> > I have complicated select query
>> > how to get prior number of records
>> > returned from this query.
>> > One number, to decide
>> > if records should be loaded.
>> >
>> > Thanks
>> > Konrad
>> >
>> >
>>
>>
>
> 


Relevant Pages

  • Re: Runtime error 2001
    ... the Where clause so that I could see as it was ... I can get the query to run with these criterion ... however I cannot seem to write the query via SQL and get it to run. ... you can execute that exact same SQL successfully then it's something else. ...
    (microsoft.public.access.modulesdaovba)
  • RE: selecting a value based on a date
    ... I still get the message "you tried to execute a query that does not include ... SO i tried replacing the having clause by the WHERE clause in the Waitdays ... chart pertaining to that dive was received. ...
    (microsoft.public.access.queries)
  • Re: query efficiency
    ... In general, the fewer phrases in the WHERE clause, the faster the query will ... execute. ... > to search for grandfathers. ...
    (microsoft.public.access.queries)
  • Re: Query occasionally returning empty results in 8i
    ... clause, second a query with where clause (executed ... Misses in library cache during parse: ... Misses in library cache during execute: ...
    (comp.databases.oracle.server)
  • RE: Any good T-SQL quick reference recommended?
    ... The full syntax of the SELECT ... SELECT Clause ... Specifies the columns to be returned by the query. ... Specifies that duplicate rows can appear in the result set. ...
    (microsoft.public.sqlserver.programming)