SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question parent_id, concatenation string values

    Hi all,

    I'm using alot tables in this form:
    Code:
    tbl {id,parent_id,title}
    
    tbl INSERT
    (1,0,'Program Your Site')
        ,(2,1,'PHP')
            ,(5,2,'PHP Application Design')
        ,(3,1,'Databases')
            ,(6,3,'MySQL')
                ,(8,6,'MySQL 5')
                ,(9,6,'MySQL 6')
            ,(7,3,'Oracle')
        ,(4,1,'Ruby')
    simple right?
    easy implement retrieve function in PHP with recursion.

    the question is if it possible to implement some SQL query that for given ID
    will return full path to the ID?
    Code SQL:
    SELECT ... AS full_path FROM tbl WHERE id=9

    The output:
    Code:
    Program Your Site :: Databases :: MySQL :: MySQL 6
    isn't there some generic solution for this problem in SQL?

    I even will do fine with list of all ID orders from the father to the last child?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    there is one way -- store your data with a different data model

    see http://www.sitepoint.com/article/hie...data-database/
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

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
  •