开发者

Mysql retrieve all rows with limit

开发者 https://www.devze.com 2022-12-20 20:28 出处:网络
I want to retrieve all rows of a particular user with limit 0,x.. So i just want to ask is there any way to retrieve all rows in mysql without calling a method which returns count(id开发者_运维问答)

I want to retrieve all rows of a particular user with limit 0,x..

So i just want to ask is there any way to retrieve all rows in mysql without calling a method which returns count(id开发者_运维问答) of x& without making an overload of existing function which does not have limit at all in query & withour string.Relace() functionality.

As internally mysql is might using this when we check show all check Box then all rows of taht table are displayed


To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

This can be found in mysql developers documentation. http://dev.mysql.com/doc/refman/5.0/en/select.html


Simple solution is sending int's max range to method i.e 2147483647 as it is same in both mysql & c# (4 bytes) can use int.MaxValue .

see references:

  1. http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html
  2. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types.


If you want to retrieve all rows, you just don't use the LIMIT clause..


WHY ONE MIGHT NEED THIS:

One Scenario which one might want to use this is while doing server side pagination.

For example, if one wants to retrieve a specific number of results per page: he may dynamically write the query as follows:

  'select * from users limit '+ perPage`

But what should perPage be if he wants all results?

A SIMPLE SOLUTION:

limit = (perPage=='x')?'':'limit'+perPage

now write the query as 'select * from users' + limit. and If you want all the results, make sure value of perPage is 'x'.

0

精彩评论

暂无评论...
验证码 换一张
取 消