Selecting all records using SQL LIMIT and OFFSET query Selecting all records using SQL LIMIT and OFFSET query postgresql postgresql

Selecting all records using SQL LIMIT and OFFSET query


From the MySQL documentation:

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;

So getting all rows might look as follows:

SELECT * FROM tbl LIMIT 0,18446744073709551615;


This may not be the best way to do it, but its the first that comes to mind...

SELECT * FROM myTable LIMIT 0,1000000

Replace 1000000 with some adequately large number that you know will always be larger than the total number of records in the table.


I used this code in nodeJS with MySQL and it's run well, It's may help you.Why you use it?

  1. It's reliable because it's a string that will append with query.
  2. If you want to set limit then you can put the limitation with the variable otherwise pass 0 with variable.

    var noOfGroupShow=0;  //0: all, rest according to number   if (noOfGroupShow == 0) {    noOfGroupShow = '';} else {    noOfGroupShow = ' LIMIT 0, '+noOfGroupShow;}var sqlGetUser = "SELECT `user_name`,`first_name`,`last_name`,`image`,`latitude`, `longitude`,`phone`,`gender`,`country`,`status_message`,`dob` as user_date_of_birth FROM `tb_user` WHERE `user_id`=?"+noOfGroupShow;