How to specify the parent query field from within a subquery in mySQL?

前端 未结 6 1007
心在旅途
心在旅途 2020-12-03 02:24

Is there a way to specify the parent query field from within a subquery in mySQL?

For Example:
I have written a basic Bulletin Board type progra

6条回答
  •  無奈伤痛
    2020-12-03 03:17

    Give the tables unique names:

    $query = "SELECT a.id, (SELECT COUNT(1) FROM post_table b WHERE parent_id = a.id) as num_children FROM post_table a WHERE a.parent_id = 0";
    

提交回复
热议问题