0

Somebody please tell me. If I create some simple pager with filter i've got two queries...

1:

Select id 
FROM blablabla 
WHERE d="example_filter" 

and in php just call rowCount() and there I'LL take num of returnin rows for my pager

2 My full select with many selected elements like:

Select id,page,title,another_elem FROM blablabla WHERE d="example_filter" LIMIT 10,20

But but this causes large load.. How I can correct it? I need to query returned an exact number of rows to fit my pager filter

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
Logan
  • 21
  • 3
  • [Possible duplicate of this question?](http://stackoverflow.com/questions/5060366/mysql-fastest-way-to-count-number-of-rows) – Ash Apr 16 '16 at 19:39
  • thnx but no. I need to optimize my query with filter first it's total num of records, and second it's pager with filter and prepared limit – Logan Apr 16 '16 at 19:49

2 Answers2

0

You can use the SQL COUNT function for the first query:

SELECT COUNT(*) FROM blablabla WHERE d="example_filter"

With this you will be able to get the number of rows matching your filter without having to load all of them. As it can be seen here, it will even work with multiple tables: http://dev.mysql.com/doc/refman/5.5/en/group-by-functions.html#function_count

Davi Alexandre
  • 11
  • 1
  • 1
  • 5
0

But my filter also retrieves data from other tables, for example to compareDetail in real code))))

Logan
  • 21
  • 3