Re: limit

From: Jens-Christian Skibakk <jens(at)cultus(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: limit
Date: 2002-11-01 10:19:02
Message-ID: qysw9.170$KE.25320@news4.ulv.nextra.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Paul Ottar Tornes wrote:

> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_00B3_01C2813F.1EFB1790
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> How come=20
> $query =3D "SELECT id, tittel, dato, kilde, referat FROM nyheter
> order =
> by id desc limit 0,10";
> Does not display any posts in my news script, but
> $query =3D "SELECT id, tittel, dato, kilde, referat FROM nyheter
> order =
> by id desc limit 10";
> Shows the last 10.?
>
> And:
>
> How come
> $query =3D "SELECT id, tittel, dato, kilde, referat FROM nyheter
> order =
> by id desc limit 10,20";
> Displays posts 5 to 14, and not 10 to 20?!
>
> Regards
>
> Paul Ottar Tornes
>
> ------=_NextPart_000_00B3_01C2813F.1EFB1790
> Content-Type: text/html;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
>
>
>
>
>
>
> How come
>
> $query =3D "SELECT id, =
> tittel,=20
> dato, kilde, referat FROM nyheter order by id desc limit 0,10";
>
> Does not display any posts in my news scri=
> pt,=20
> but
>
> $query =3D "SELECT id, =
> tittel,=20
> dato, kilde, referat FROM nyheter order by id desc limit 10";
>
> Shows the last 10.?
>
>
>
> And:
>
>
>
> How come
>
> $query =3D "SELECT id, =
> tittel,=20
> dato, kilde, referat FROM nyheter order by id desc limit 10,20";
> Displays posts 5 to 14, and not 10 to=20
> 20?!
>
>
>
> Regards
>
>
>
> Paul Ottar Tornes
>
>
> ------=_NextPart_000_00B3_01C2813F.1EFB1790--
>
>
You must use the OFFSET to do this.

Write your query this way:

$query = "SELECT id, tittel, dato, kilde, referat FROM nyheter order by
id desc offset 9 limit 10";

In response to

  • limit at 2002-10-31 23:39:22 from Paul Ottar Tornes

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Stern 2002-11-01 10:40:09 readline.h and history.h configure error
Previous Message Shridhar Daithankar 2002-11-01 10:18:57 Re: how to reset the sequences of SERIAL vars?