Re: Efficient way to count rows when using GROUP BY

From: Date: Sun, 26 Jun 2005 23:39:48 +0000
Subject: Re: Efficient way to count rows when using GROUP BY
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-39784@lists.php.net to get a copy of this message
It worked! SELECT COUNT(*) FROM (SELECT COUNT(*) FROM ad.off_enrol GROUP BY jcu_campus, sub_code) t1 Thank you list -:) Martín Marqués wrote:
El Dom 26 Jun 2005 07:39, Ross Honniball escribió:
Hi All, I use SELECT COUNT(*) FROM whatever WHERE whatever to determine how many rows a particular query will return (then use this
count to assist with pagination).
The problem is that this does not work if the query contains a GROUP BY
statement as, of course,
the query will return many rows each with a count by each grouping. Does anyone know an efficient way to determine the number of ROWS a query
with a GROUP BY
statement will return (without just executing the entire query with no LIMIT
statement)? You are not stating which database you are working with, but I would do this (don't know if it's efficient, but it'll work): SELECT sum(count) FROM (SELECT COUNT(*) AS count FROM whatever WHERE whatever) t1; Hope it helps.


« previous php.db (#39784) next »