title: Mysql find root parent of shared post
body: <p>I have to manage sharing-post like on Facebook here is how I intend to do it.</p>
  
  <p>I have a table which contains articles with a parent_id field and I would like to change state of all shared articles to 0 when parent is deleted(when parent state = 0)</p>
  
  <pre><code>articles
  
  +----+-----------+--------------+-------+--------+
  | id | content   | user_id | parent_id  | state  |
  +----+-----------+--------------+-------+--------+
  | 1  | content   | 2       | null       |   1    | 
  | 2  | content   | 5       | null       |   1    |
  | 3  | content   | 4       | 2          |   1    |
  | 4  | content   | 6       | null       |   1    |
  | 5  | content   | 7       | 1          |   1    |
  | 6  | content   | 1       | 3          |   1    |
  | ...| ...       | ...     | ...        |   ...  |
  +----------------+---------+------------+--------+
  </code></pre>
  
  <p>Example according to the articles table above:</p>
  
  <p>User 4 shares article 2 and user 1 shares article 3 which is a child of the article 2. So when article 2(root article) is deleted(his state change to 0) all child articles(3 &amp; 6) state have to also change to 0.</p>
  
  <p>How to accomplish this ? </p>
  
  <p>Any other way to manage sharing post will be great appreciated</p>