Page 1 of 1

how to get the number of rows that match a query

Posted: Fri Sep 10, 2004 5:18 am
by jasongr
Hello

I have a complicated query that uses LIMIT X,Y at the end
This causes the query to return up to Y element.
However I know that if the LIMIT was omitted, the query would have returned a much larger results set.

My quesion is this:
Is there a way of knowing how large the result set would have been without the LIMIT clause, without resorting to running two queries? one with the LIMIT (to get the items I need) and another without the LIMIT (to see how many items could potentially match the query)

thanks

don't think so

Posted: Fri Sep 10, 2004 5:29 am
by phpScott
Not that I'm aware off.
Maybe one of the php/mysql guru's around here tell you different.
Other wise sorry.

Posted: Fri Sep 10, 2004 5:32 am
by m3mn0n
You'd need two queries.

A count() one, and a SELECT one.

Posted: Fri Sep 10, 2004 6:40 am
by Weirdan
Sami wrote:You'd need two queries.

A count() one, and a SELECT one.
Sami, you can't use count() for queries with GROUP BY clause this way. So, one SELECT without LIMIT followed by [php_man]mysql_num_rows[/php_man]() and then SELECT with LIMIT clause.