Is there a more efficient way of making pagination in Hibernate than executing select and count queries?

前端 未结 11 1315
说谎
说谎 2020-12-04 16:36

Usually pagination queries look like this. Is there a better way instead of making two almost equal methods, one of which executing \"select *...\" and the other one \"count

11条回答
  •  自闭症患者
    2020-12-04 17:13

    There is a way

    mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
        -> WHERE id > 100 LIMIT 10;
    mysql> SELECT FOUND_ROWS();
    

    The second SELECT returns a number indicating how many rows the first SELECT would have returned had it been written without the LIMIT clause.

    Reference: FOUND_ROWS()

提交回复
热议问题