Forum Moderators: coopster

Message Too Old, No Replies

MySQL Count with Limits

Counting MYSQL records when query has limits

         

Tourex

2:58 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



What is the most efficient way of counting the total record in a MySQL table when the actual query is going to have a LIMIT applied?

Until now I've been doing two queries - the first to count the total records in the table that conform to the WHERE condition; then a second query to get the actual data records, limiting the search to x records per query. It strikes me that there's probably a way to get the total without running two queries.

Any help would be appreciated.

coopster

3:38 pm on Dec 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The MySQL FOUND_ROWS() [dev.mysql.com] function is exactly what you are looking for ...