How to count and limit record in a single query in MYSQL?

后端 未结 5 2034
刺人心
刺人心 2020-12-14 09:46

I am searching for records in a table as follows:

SELECT Id, Name FROM my_table WHERE Name LIKE \'%prashant%\' LIMIT 0, 10;

Now, I am addin

5条回答
  •  既然无缘
    2020-12-14 10:19

    In case of huge tables and selecting multiple fields (not just Id, Name as in your example) i would recommend to use 2 queries. Selecting count(0) first with all those WHERE clauses and only then build the pagination, selecting data etc. It will work really faster on some popular eCommerce website, for example.

提交回复
热议问题