tags:

views:

133

answers:

4

Hello, i have an sql query that selects a bunch of data. I would also like to get the number of records selected by the query (before i limit it). All the examples i have seen of the count statment duplicated the select. My select statment is about 50 lines long and i would rarther not duplicate it.

Thanks

+1  A: 

Your question would be easier to answer if you could give us an example SQL statement, however, from what you have said so far, the following should be correct:

Select Columns, Count(Distinct Value) From Table Where x=y Group By Columns
GateKiller
A: 

It isn't really possible to get the number of rows that a query would return without running it or a version of it.

There's sql_calc_found_rows which will let you put a limit clause on the statement and return the total number of rows it would have found had there not been a limit clause in a subsequent call to found_rows(), but it's expensive.

ʞɔıu
A: 

Thanks everyone, i was just trying out sql_calc_found_rows, and your dam right Nick, it is expensive. I think ill just create a separte query, thanks