Re: need assistance with multi-row matching expression

From: Mark Stosberg <mark(at)summersault(dot)com>
To: Nick Fankhauser <nickf(at)ontko(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: need assistance with multi-row matching expression
Date: 2002-08-19 17:13:24
Message-ID: Pine.BSF.4.44.0208191206040.75440-100000@nollie.summersault.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Mon, 19 Aug 2002, Nick Fankhauser wrote:
>
> This may not be the best way, but I couldn't resist taking a shot at it...

Thanks for the response Nick. If only I knew I was going to get a
response from a block away, I would have just come down to say hi. :)

I had an "a ha" moment about this over lunch. I was making the problem
much harder than it needed to me, having assured myself I was going to
need some advanced SQL feature to solve the problem. Some testing seems to
reveal that I can address this problem simply by joining against the
park_feature_map table N times. This way I only need to match against 1
row each of these tables, which is easy in SQL. Here's my statement I
tested with for N=2:

SELECT p.park_id, park_name
FROM parks p
JOIN park_feature_map map_4
ON (p.park_id = map_4.park_id AND map_4.feature_id=4)
JOIN park_feature_map map_15
ON (p.park_id = map_15.park_id AND map_15.feature_id=15);

In this way, I'm only returned the parks that match all the features.
Thanks again for your help!

-mark

http://mark.stosberg.com/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Darrin Domoney 2002-08-19 17:34:53 Urgent - SQL Unique constraint error (long)
Previous Message Nick Fankhauser 2002-08-19 16:52:43 Re: need assistance with multi-row matching expression