SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: sql problem

  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sql problem

    I want to ask something that I know that rather it is not possible.
    I have a table (categories) that has a foreign key to thatself.(one->many).
    I want to take all the chain of a category (A category and all the subcategories).It is possible with a single view?
    I thing it is possible with a Stored Routine.

  2. #2
    From Italy with love bronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    8,604
    Mentioned
    76 Post(s)
    Tagged
    4 Thread(s)
    If the chain has a limited max depth (say 3), then you might join the table three times (LEFT OUTER JOIN). But it wouldn't be flexible.
    If there's no fixed limit to the depth, it's not possible as far as I know.

  3. #3
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    joins up to 15 levels deep works quite effectively

    see Categories and Subcategories
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •