List Info

Thread: RE: Querying postgres directly from outside app




RE: Querying postgres directly from outside app
user name
2007-05-14 15:04:29
> I think that would be a UNION.
> Also it would add extra rows to the count
> for each story with more than one keyword.

Scott, you're correct.

In an attempt to create a query that lists all the related
keywords of a
given keyword, I came up with this monstrosity:

SELECT name FROM keyword WHERE id IN (SELECT DISTINCT
keyword_id FROM
story_keyword WHERE story_id IN (SELECT story_id FROM
story_keyword,
keyword WHERE keyword_id = keyword.id AND keyword.name IN
('Oil')));

I imagine there has to be a more elegant solution. If so,
I'm all ears!

Chris





RE: Querying postgres directly from outside app
user name
2007-05-15 03:26:16
On Mon, 14 May 2007, Chris Schults wrote:
> In an attempt to create a query that lists all the
related keywords of a
> given keyword, I came up with this monstrosity:
>
> SELECT name FROM keyword WHERE id IN (SELECT DISTINCT
keyword_id FROM
> story_keyword WHERE story_id IN (SELECT story_id FROM
story_keyword,
> keyword WHERE keyword_id = keyword.id AND keyword.name
IN ('Oil')));

Please put things like this on
http
://wiki.bricolage.cc/bin/view/Bric/UsefulSQL


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )