X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 314E2D1C47A for ; Mon, 11 Aug 2003 19:41:58 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35028-01 for ; Mon, 11 Aug 2003 16:40:25 -0300 (ADT) Received: from mail.tvnetwork.hu (zion.tvnetwork.hu [80.95.64.67]) by svr1.postgresql.org (Postfix) with SMTP id 88813D1C4E1 for ; Mon, 11 Aug 2003 16:41:43 -0300 (ADT) Received: (qmail 8395 invoked by uid 64014); 11 Aug 2003 19:41:43 -0000 Received: from fejes@tvnetwork.hu by zion by uid 64011 with qmail-scanner-1.16 (spamassassin: 2.20. Clear:. Processed in 0.019051 secs); 11 Aug 2003 19:41:43 -0000 Received: from ip-165.c-200.tvnetwork.hu (HELO FAITH) (62.165.200.165) by zion.tvnetwork.hu with SMTP; 11 Aug 2003 19:41:43 -0000 Message-ID: <000a01c36040$9c2b9060$a5c8a53e@FAITH> From: "Fejes Jozsef" To: Subject: possible? Date: Mon, 11 Aug 2003 21:41:50 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/105 X-Sequence-Number: 14721 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?