Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8A4D6475AFF for ; Sat, 23 Nov 2002 07:42:04 -0500 (EST) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by postgresql.org (Postfix) with ESMTP id CC74E4758C9 for ; Sat, 23 Nov 2002 07:42:03 -0500 (EST) Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18FZZr-0005De-00 for ; Sat, 23 Nov 2002 13:40:03 +0100 To: pgsql-sql@postgresql.org X-Injected-Via-Gmane: http://gmane.org/ Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18FZR9-0004wl-00 for ; Sat, 23 Nov 2002 13:31:03 +0100 Path: not-for-mail From: "Arcadius A." Subject: LIMIT and/or GROUP BY help! Date: Sat, 23 Nov 2002 13:33:03 +0100 Lines: 37 Message-ID: NNTP-Posting-Host: viking.sh.cvut.cz X-Trace: main.gmane.org 1038054663 19018 147.32.124.181 (23 Nov 2002 12:31:03 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 23 Nov 2002 12:31:03 +0000 (UTC) X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/384 X-Sequence-Number: 10526 Hello! I hope that someone here could help. I'm using PostgreSQL7.1.3 I have 3 tables: entry, subcategory and category. The table "entry" has a foreign key "subcategoryid" with reference to the table "subcategory", and the "subcategory" table has a foreign key "categoryid" with reference to the table "category" I have the following SQL query : "SELECT * FROM entry where isapproved='y' AND subcategoryid IN (SELECT id FROM subcategory WHERE categoryid='"+catID+"') ORDER BY subcategoryid DESC"; For a given categoryid, this will return all entries in the "entry" table having a corresponding subcategoryid(s). But I want to return only a limited number of entries of each subcategory..... let's say that I want to return at most 5 entries of each subcategory type ( for instance if the inner subquery returns 3 results, thus I will be having in total at most 15 entries ).... How can this be achieved? I'm aware of postgreSQL "LIMIT" and "GROUP BY" clause..... but so far, I'm not able to put all this together... Thanks in advance. Arcadius.