Slashdot Query - Mailing list pgsql-sql

From Chris Bitmead
Subject Slashdot Query
Date
Msg-id 3757459C.F0E63B5E@bigfoot.com
Whole thread Raw
In response to Group By Dilemma  ("Tim Perdue" <perdue@raccoon.com>)
Responses Re: [SQL] Slashdot Query
List pgsql-sql
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.


pgsql-sql by date:

Previous
From: "Tim Perdue"
Date:
Subject: Group By Dilemma
Next
From: nathan@khmere.com
Date:
Subject: Embedded SQL in 'C'