Received: from localhost.localdomain (h246.ozemail2.ozemail.com.au [203.108.14.246] (may be forged)) by hub.org (8.9.3/8.9.3) with ESMTP id XAA59270 for ; Thu, 3 Jun 1999 23:19:01 -0400 (EDT) (envelope-from chris.bitmead@bigfoot.com) Received: from bigfoot.com (localhost [127.0.0.1]) by localhost.localdomain (8.8.7/8.8.7) with ESMTP id NAA07436 for ; Fri, 4 Jun 1999 13:18:53 +1000 Sender: chris@localhost.localdomain Message-ID: <3757459C.F0E63B5E@bigfoot.com> Date: Fri, 04 Jun 1999 13:18:53 +1000 From: Chris Bitmead X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.2.6 i686) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@hub.org Subject: Slashdot Query References: <001801beae2c$354dd580$0b8c5aa5@timnt.weather.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I want to do a query that is like the icons on the top of http://slashdot.org. That is I want to select the 5 most recent distinct categories from a bunch of stories. So I have... SELECT DISTINCT category.oid, category.title, category.image FROM story, category* WHERE story.category = category.oid AND story.approved ORDER BY datetime DESC LIMIT 5; The trouble is it doesn't return distinct results, but rather it returns duplicates. Any ideas how I can do this query? I thought there might be some sub-select solution, but I don't really understand subselects. I thought of, SELECT distinct * from (SELECT category.oid, category.title, category.image FROM story, category* WHERE story.category = category.oid AND story.approved ORDER BY datetime DESC )LIMIT 5; But that doesn't work in any shape or form.