Results 1 to 5 of 5

Thread: Hierarchy query

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Unanswered: Hierarchy query

    hi all!
    am trying to develop a hierarchy tree in MySQL such that it show something like this
    Stationary
    Pencils
    Printing Paper
    Staples
    Meats and Fish
    Chicken
    Fillet
    Samosas

    This is are the levels

    data level
    ------ -----
    root 0
    Stationary 1
    Pencils 2
    Printing Paper 2
    Stapes 2
    Meats and Fish 1
    Chicken 2
    Fillet 2
    Samosas 2

    I have never used SQL hierarchical query...i am new to this...
    Can someone explain the SQL hierarchical query, how it is implemented and how can could apply it to my query

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Best thing is to have a look at this Hierarchical query in MySQL: limiting parents | EXPLAIN EXTENDED which explains how this can be achieved in MySQL. Unfortunately MySQL does not have SELECT statements that allow this with START WITH ... CONNECT BY.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Feb 2012
    Posts
    2
    really? i didnt know MySQL cannot run sql hierarchies. thanks for the information

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Hawi-Z View Post
    i didnt know MySQL cannot run sql hierarchies.
    depends what you mean by "run sql hierarchies"

    you most certainly can store hierarchies in mysql tables, and you can also quite easily retrieve hierarchical information

    (the ease is largely determined by which model you implement)

    i think what you might have been trying to say is that mysql does not support query recursion, but recursion is only one way to retrieve a hierarchy

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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