[thelist] Multi-level data storage

rudy r937 at interlog.com
Wed Feb 28 08:54:08 CST 2001


> Does MySQL syntax include an easier or more efficient
> way to do this?


hi simon

well, i dunno about "easier"  ;o)

it requires a three-way table join

the m-m table provides the associations between links and categories, and
you will also want to get data columns from each of the links and
categories tables, hence you need to access all three in the query

here's the query for listing all the links in a particular category --

   select CatName, Url, LinkName, Description
    from Categories, LinkCats, Links
    where Categories.CatID = LinkCats.CatID
        and LinkCats.LinkID = Links.LinkID
       and CatID = #selectedcategory#

here's the query for listing all the categories that a particular link is
found in --

   select Url, LinkName, Description, CatName
    from Links, LinkCats, Categories
    where Links.LinkID = LinkCats.LinkID
        and LinkCats.CatID = Categories.CatID
        and LinkID = #selectedlink#

shout if you need these explained further...


rudy





More information about the thelist mailing list