Getting a total hit number and a LIMIT number at the same time

From: <jeff(dot)fitzmyers(at)managestar(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Getting a total hit number and a LIMIT number at the same time
Date: 2001-05-09 17:11:04
Message-ID: 371EAC487A83CD4296F6999FD088D8331B7084@atlas.managestar.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table with 5,000 rows in it. I also have a query that returns
about 950 rows, but I only want items 50-60 from that match.
What I want to show the user is
- the total # of matches (950)
- the 10 rows that I want

The following works, but can it be reduced to a single query?

SELECT COUNT(*) FROM ... WHERE ...
(print out the total number of matches)

SELECT * FROM ... WHERE ... OFFSET 50 LIMIT 10
(print out the 10 rows)

pg_cmdtuples($result) shows the number of *affected* tuples.

Thanks, Jeff

Browse pgsql-general by date

  From Date Subject
Next Message Tony Grant 2001-05-09 17:35:02 Moving to 7.1.1
Previous Message Janning Vygen 2001-05-09 17:04:31 updating rows while selecting