Re: select count(*) and limit

From: Oscar Rodriguez Fonseca <info(at)vraniscci(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: select count(*) and limit
Date: 2006-05-18 11:27:53
Message-ID: 20060518132753.6666a4d6@vrlap.localvrnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

El día Thu, 18 May 2006 12:51:10 +0200
Verena Ruff <lists(at)triosolutions(dot)at> escribió:

> sometimes I have queries with a LIMIT statement. Now I'd like to present
> the user the returned records and inform him how many records there are
> if there was no LIMIT statement. Is it possible to get all neccessary
> information with one query?
> This works:
> SELECT * FROM table LIMIT 20
> SELECT count(*) FROM table
> But is it possible to have one query returning both, the records and the
> count?

A surely _INEFFICIENT_ way of doing it:


SELECT t.*,c.count FROM table AS t FULL OUTER JOIN (SELECT count(*) FROM
table) AS c ON true LIMIT 20;

This will add a 'count' column at the end of each row (with the same value for all).

But I do not get the point of the query.

Regards,

--
Oscar

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Verena Ruff 2006-05-18 12:18:07 Re: select count(*) and limit
Previous Message Oscar Rodriguez Fonseca 2006-05-18 11:13:46 Re: selecting un-ordered rows