2

I am using server side pagination.For that initially i need to show first 100 records first and the no of buttons on the top.For example total i have 550 records i need to show 6 buttons at the top.When user clicks on second button i need to retrieve 101 to 199 records.

To get the total records i am using one database call and to get the first 100 records i am using another database call.

I am using hibernate ,so the query is like this

 select model from TableName model where ................

   FirstResult = 0
   MaxResult = 100

And to get the total no of records i am using

   select count(*) from TableName model where ................

Here the problem is i am running the similar query for 2 times. How i can combine these 2 queries into one?

Thanks in advance...

4

3 回答 3

0
SELECT *, (SELECT COUNT(*) FROM `TableName`) FROM `TableName`

有效,但有 2 个查询

(服务器版本:5.5.32-MariaDB-1~precise-log - mariadb.org 二进制分发版)

于 2013-08-27T05:04:39.697 回答
0

你可以在 mysql http://dev.mysql.com/doc/refman/5.0/en/union.html中使用联合

像这样组合 从 TableName 模型中选择模型 where ...... UNION 从 TableName 模型中选择 count(*) where ...... .

但是您必须注意分离两个查询的结果

于 2013-08-27T05:05:47.217 回答
0

这不是同一个查询,但条件非常相似。用普通条件调用 2 个查询并没有错。

于 2013-08-27T05:00:07.913 回答