How to write select query to get all child id by parent id in mysqli
<p>I am trying to get all child ids by parent id from a single table.
Below is my table <code>course</code>:</p>

<p><img src="https://i.stack.imgur.com/XsMed.png" alt="enter image description here"></p>

<p>Here is my code:</p>

<pre><code>public function getLeftMenuMainCategoryInfoFromDb()
{
    $sqlQuery = "SELECT p.course_id AS parent_id ,p.course_name As parent_coursename ,c.course_id AS child_id ,c.course_name As child_coursename FROM course As p LEFT JOIN course As c ON c.course_parent_id = p.course_id WHERE p.course_parent_id = 0 ORDER BY p.course_id";
    $result = $this-&gt;selectQuery($sqlQuery);
    //print_r($result);
    return $result;

}
</code></pre>