List:General Discussion« Previous MessageNext Message »
From:Gleb Paharenko Date:September 7 2005 2:04pm
Subject:Re: Getting Record Count w/o doing 2 queries.
View as plain text  
Hello.

You want to check out the FOUND_ROWS() function: 
http://dev.mysql.com/doc/mysql/en/information-functions.html

BTW, similar question was asked recently.


pow <powster@stripped> wrote:
> Hi everyone, Im executing the following query:
> 
> SELECT *
> FROM
> table1
> WHERE
> table1.field1 = 'A' AND table1.field2 = 'B'
> LIMIT 0,10
> 
> I also need to get the total record count for the above query, but 
> without the limit clause (limit is for pagination purposes)
> Is there any way to extract this total record count without the need to 
> do another query?
> 
> Right now I am using another query to get the total record count:
> 
> SELECT COUNT(*)
> FROM
> table1
> WHERE
> table1.field1 = 'A' AND table1.field2 = 'B'
> 
> 
> In reality, my tables are very large, and involve joins, so executing 
> the query TWICE is taking its toll on the server.
> Thanks!
> Pow
> 


-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Gleb Paharenko
 / /|_/ / // /\ \/ /_/ / /__   Gleb.Paharenko@stripped
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.NET
       <___/   www.mysql.com



Thread
Getting Record Count w/o doing 2 queries.pow7 Sep
  • Re: Getting Record Count w/o doing 2 queries.Eric McGrane7 Sep
  • Re: Getting Record Count w/o doing 2 queries.Brent Baisley7 Sep
  • Re: Getting Record Count w/o doing 2 queries.Gleb Paharenko7 Sep
  • Re: Getting Record Count w/o doing 2 queries.SGreen7 Sep
    • Re: Getting Record Count w/o doing 2 queries [sorry, left out onemajor piece of info]pow7 Sep
      • Re: Getting Record Count w/o doing 2 queries [sorry, left out one majorpiece of info]SGreen7 Sep