Re: select count(*) and limit - Mailing list pgsql-novice

From Oscar Rodriguez Fonseca
Subject Re: select count(*) and limit
Date
Msg-id 20060518132753.6666a4d6@vrlap.localvrnet
Whole thread Raw
In response to select count(*) and limit  (Verena Ruff <lists@triosolutions.at>)
Responses Re: select count(*) and limit
List pgsql-novice
El día Thu, 18 May 2006 12:51:10 +0200
Verena Ruff <lists@triosolutions.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

pgsql-novice by date:

Previous
From: Oscar Rodriguez Fonseca
Date:
Subject: Re: selecting un-ordered rows
Next
From: Verena Ruff
Date:
Subject: Re: select count(*) and limit