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

后端 未结 5 2035
刺人心
刺人心 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:22

    MySQL supports doing this using SQL_CALC_FOUND_ROWS as mentioned by Ionut. However, it turns out that in many cases it's actually faster to do it the old fashioned way using two statements, where one of them is a regular count(). This does however require that the counting can be done using an index scan, which won't be the case for this very query, but I thought I'd mention it anyway.

提交回复
热议问题