title: How can a child tell which parent is its own in SQL?
body: <p>I have a very quick question about a previous post that was answered. I would have posted i there but since it was already answered i think it is archived or somewhere in the annals of SO.</p>
  
  <p>In regards to the chosen answer of the post below, how do i create my database so that it can determine a child's specific parent?</p>
  
  <p>i.e. in the link below the answerer used the example of assigning "0" to home, "1" to furniture, garden, and "2" to lawn care. So if i were to click on lawn care how would the database know that the parent was "garden" and not "furniture, since their parent id is both 1?</p>
  
  <p><a href="https://stackoverflow.com/questions/12556657/how-do-i-create-a-directory-for-a-product-catalogue-im-making">How do i create a directory for a product catalogue im making?</a></p>
  
  <p>The database table would look like this:</p>
  
  <pre><code>Categories
  id | parent_id | name
  1  | 0         | Home
  2  | 1         | Garden
  3  | 1         | Furniture
  4  | 1         | Plumbing
  5  | 2         | Lawn Care
  </code></pre>
  
  <p>This would equate to a hierarchy like the following:</p>
  
  <ul>
  <li>Home
  
  <ul>
  <li>Garden
  
  <ul>
  <li>Lawn Care</li>
  </ul></li>
  <li>Furniture</li>
  <li>Plumbing</li>
  </ul></li>
  </ul>