X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 94D4D474E61 for ; Mon, 3 Mar 2003 14:12:26 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 80711-03 for ; Mon, 3 Mar 2003 14:12:23 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id DC537475925 for ; Mon, 3 Mar 2003 14:12:23 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 8D97743B056; Mon, 3 Mar 2003 14:12:22 -0500 (EST) From: cprice@hrdenterprises.com (Chris) X-Newsgroups: comp.databases.postgresql.sql Subject: LIMIT and SUBQUERIES Date: 3 Mar 2003 10:54:34 -0800 Organization: http://groups.google.com/ Lines: 25 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 X-Complaints-To: groups-abuse@google.com To: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/123 X-Sequence-Number: 12163 Hi all, This question may be a bit confusing, and it is entirely possible that I am going about it the wrong way, but any suggestions would be much appreciated. I'm trying to query a table of records that has a (simplified) structure like the following: owner int description text amount double I want to do a select that returns the TOP 5 records ordered by amount, PER OWNER. I can easily construct this SQL query, the problem arises in the fact that I want to have groups of the top five per owner (an owner can obviously have more than 5 records, but I just want the top 5 for each). So anyway, I have the query that is working - but it returns all records for all owners, when what I really want to do is return the top 5 per each owner. Any suggestions? Thanks Chris