List:General Discussion« Previous MessageNext Message »
From:pow Date:September 7 2005 6:33pm
Subject:Re: Getting Record Count w/o doing 2 queries [sorry, left out one
major piece of info]
View as plain text  
Very sorry for having troubled all regarding the seemingly stupid rtfm 
garnering request for help.

But in my attempt to make the question as simple and succinct as 
possible, i forgot to state one EXTREMELY important chunk of information.

I can't use SQLCALCFOUNDROWS because there is a subqry in my statement.
SQLCALCFOUNDROWS does not like being in the subqry, always gives me an 
error (it runs fine as a standalone query though)

The total row count has to be from the subqry, because thats where the 
LIMIT is.

Many thanks and apologies.

SGreen@stripped wrote:

>
> RTFM - It is online, it has an index, and it is searchable: 
> http://dev.mysql.com/doc/mysql/en/select.html (hint: look for the 
> phrase "how many rows" on this page)
>
> If you looked in the index for "rows", you would find the function 
> ROW_COUNT() (which is close but not exactly what you wanted). However, 
> by clicking on the link next to that function, you wind up at another 
> page that also has the answer you seek.
>
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine
>
>
>
> pow <powster@stripped> wrote on 09/07/2005 06:15:12 AM:
>
> > 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
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
> >


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