Re: get certain # of recs

Поиск
Список
Период
Сортировка
От Jason Earl
Тема Re: get certain # of recs
Дата
Msg-id 20010914213609.38106.qmail@web10005.mail.yahoo.com
обсуждение исходный текст
Ответ на get certain # of recs  ("Mike S. Nowostawsky" <mikenowo@sympatico.ca>)
Список pgsql-general
What you want is something like this:

SELECT * FROM tablename LIMIT 21;

This query will return 21 records, but there is no
guarantee which 21 tuples it will return.  Most people
generally add a sort to this type of query so that
they get the records that they want.  For example, I
use a query like this all of the time:

SELECT * FROM caseweights ORDER BY dt DESC LIMIT 10;

In this query dt is a timestamp column, and so this
gives me the 10 latest records in reverse order (from
newest to oldest).  PostgreSQL is very clever about
using the indexes on these queries, and so this is my
method of choice for getting the "most recent"
additions to the table.

Hope this is helpful,

Jason

--- "Mike S. Nowostawsky" <mikenowo@sympatico.ca>
wrote:
> How can one select only a certain number of records
> in Postgres?
>
> In other SQL langs we can use, say, for the first 20
> recs:
>
> select  * from tablename where rownum < 21;
>
> WHAT should 'rownum' be to make this select work...
> OR is there a diff
> syntax?
>
> Thx,
> --
> =============================================
>  Mike S. Nowostawsky:
>  Email: mikenowo@sympatico.ca, mikenowo@yahoo.ca
>  Home Page: http://www3.sympatico.ca/mikenowo/
>  Lachine (Montreal), Quebec, Canada
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please
> send an appropriate
> subscribe-nomail command to majordomo@postgresql.org
> so that your
> message can get through to the mailing list cleanly


__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

В списке pgsql-general по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: get certain # of recs
Следующее
От: lbayuk@mindspring.com (ljb)
Дата:
Сообщение: Re: Strange select query