possible? - Mailing list pgsql-sql

From Fejes Jozsef
Subject possible?
Date
Msg-id 000a01c36040$9c2b9060$a5c8a53e@FAITH
Whole thread Raw
Responses Re: possible?
List pgsql-sql
Hi!

I'd like to make a bulletin board, and came upon a strange question: can the
forum listing be done only with one single SELECT?

My data structure is like this. Table "forum" holds the main categories,
each with an "id" field. Table "thread" holds the threads, each has it's own
"id" too, and a "forumid" field that specifies it's parent caregory. Table
"post" holds the posts, with "id", and with a "threadid" field, that
specifies which thread this post belongs to, and also each post has a
timestamp.

First the user should see a listing of the "forum" table. Then he selects a
forum, and he should see the a listing of the "thread" table with the
appropriate "forumid". It's not too serious so far.

Here are my problems:
- order the listings by the time the last post was made
- display how many posts that "forum" or "thread" contains
- for forums, display how many threads are in it

I checked out some forum implementations so far, and found nothing helpful.
They use too many queries, or don't order by time (like PHPBB). On the main
page, I can list the forums, and then make a query for each of them to tell
how many threads and posts are in it, but I just don't like it. By creating
views, I was even able to order by time, but couldn't tell the number of
threads. Also, after creating a new thread, it's empty, so "WHERE forum.id =
thread.forumid AND thread.id = post.threadid" doesn't return empty threads,
so noone can post to it.

What I'd really love to see is a single SELECT statement for each of the two
listings that display everything I want. With data views, embedded selects,
or anything. So, is it possible?




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query suddenly taking longer....
Next
From: Kurt Overberg
Date:
Subject: Re: Query suddenly taking longer....