Skip site navigation (1) Skip section navigation (2)

Return column value from previous and next row in a recordset

From: "Matt Arnilo S(dot) Baluyos (Mailing Lists)" <matt(dot)baluyos(dot)lists(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Return column value from previous and next row in a recordset
Date: 2006-02-12 09:09:04
Message-ID: d1a6d7930602120109h33a4cc44ncb6f98c17f366221@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello everyone,

I'm trying to implement a sort of Master-Detail functionality in a
website. I have a page that displays a list of articles. Clicking on
an item in that page will show more detailed information on that
article.

What I'd like to be able to do is to be able to put in "Previous" and
"Next" links on that detailed page - and I'd like to do that without
an additional query to the database just to determine the previous and
next article's IDs.

I was thinking if there'd be a way to do return a recordset such as this one:

article_id | article_title | previous_article_id | next_article_id
1               article1                NULL                  2
2               article2                1                        3
3               article3                2                        4
4               article4                3                        NULL

Any pointers would be greatly appreciated.

Thanks and best regards,
Matt

--
Stand before it and there is no beginning.
Follow it and there is no end.
Stay with the ancient Tao,
Move with the present.

Responses

pgsql-novice by date

Next:From: Ken HagansDate: 2006-02-13 03:42:55
Subject: Re: Return column value from previous and next row in a recordset
Previous:From: ccrupperDate: 2006-02-12 06:01:28
Subject: Can't Find Any Tables with DatabaseMetaData.getTables()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group