OT : SQL query help.

From: "Arcadius A(dot)" <ahouans(at)sh(dot)cvut(dot)cz>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: OT : SQL query help.
Date: 2002-11-23 11:49:21
Message-ID: 005001c292e6$5c95a6c0$b57c2093@sh.cvut.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello!
I think....my question is a bit off topic here .... it's rather a pure SQL
issue.... but 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 :

String qStr="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.

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2002-11-23 14:22:52 Re:
Previous Message pginfo 2002-11-23 10:44:13 Re: