How to limit rows in PostgreSQL SELECT

前端 未结 5 973
盖世英雄少女心
盖世英雄少女心 2021-02-06 20:21

What\'s the equivalent to SQL Server\'s TOP or DB2\'s FETCH FIRST or mySQL\'s LIMIT in PostgreSQL?

5条回答
  •  名媛妹妹
    2021-02-06 21:09

    You could always add the OFFSET clause along with LIMIT clause.

    You may need to pick up a set of records from a particular offset. Here is an example which picks up 3 records starting from 3rd position:

    testdb=# SELECT * FROM COMPANY LIMIT 3 OFFSET 2;
    

    This would produce the following result:

     id | name  | age | address   | salary
    ----+-------+-----+-----------+--------
      3 | Teddy |  23 | Norway    |  20000
      4 | Mark  |  25 | Rich-Mond |  65000
      5 | David |  27 | Texas     |  85000
    

    Full explanation and more examples check HERE

提交回复
热议问题