Thread: limit 0,10 within SELECT ..... FROM ......

limit 0,10 within SELECT ..... FROM ......

From
"Paul Ottar Tornes"
Date:
I run PostgreSQL and have some questions:

 
How come
    $query = "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 = "SELECT id, tittel, dato, kilde, referat FROM nyheter order by id desc limit 10";
Shows the last 10.?
 
And:
 
How come
    $query = "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

Re: limit 0,10 within SELECT ..... FROM ......

From
Darren Ferguson
Date:
You should use offset this will help you in this

Select id, tittel, dato, kilde, referat FROM nyheter order by id desc
limit 5 offset 5

will return 5 - 9 i think or 10 but this is how you should use it

do \h select when in psql interface to view select command

HTH
On Fri, 1 Nov 2002, Paul Ottar Tornes wrote:

> I run PostgreSQL and have some questions:
>
>
> How come
>     $query = "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 = "SELECT id, tittel, dato, kilde, referat FROM nyheter order by id desc limit 10";
> Shows the last 10.?
>
> And:
>
> How come
>     $query = "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
>

--
Darren Ferguson


limit 0,10 within SELECT ..... FROM ......

From
Lee Kindness
Date:
Probably because you're really wanting to do:

 SELECT id, tittel, dato, kilde, referat
  FROM nyheter ORDER BY desc LIMIT 10, 0

(i.e. got the arguments the wrong way round) It's much more intuitive
to use the "LIMIT n OFFSET m" syntax.

Lee.

Paul Ottar Tornes writes:
 > I run PostgreSQL and have some questions:
 >
 >
 > How come
 >     $query = "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 = "SELECT id, tittel, dato, kilde, referat FROM nyheter order by id desc limit 10";
 > Shows the last 10.?
 >
 > And:
 >
 > How come
 >     $query = "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?!
 >