[thelist] SQL for what I think might be many to many
John Corry
webshot at members.evolt.org
Fri Apr 19 16:05:01 CDT 2002
I'm working on a beach guide site that will provide a directory of beaches
with information about each beach in a particular community here on Maui.
One feature I want to build is linking condos to beaches, by whether a beach
is in walking distance of a condo or not. I can't figure out the best way to
set this up in the db though. I'm the kind of guy who will not store
multiple values in one field, no matter what.
So what do I do? My only idea was:
Build a table that has columns beach_id and property_id, with 1 row for each
'match', like:
beach 1 condo 4
beach1 condo 5
beach 2 condo 12
beach 2 condo 17
beach 3 condo 7
Then to get all the condos within walking distance of beach 1, I just:
SELECT * FROM walking_distance_table WHERE beach_id = beach 1 ; and there's
my array of properties within walking distance of beach 1
I guess that same structure would support doing the same thing backwards,
selecting beaches with walking distance of a condo
Is that the best way?
thanks,
John
More information about the thelist
mailing list