參考 自己 join 自己 SELECT a.id, count( b.parent_id ) FROM table1 a LEFT JOIN table2 b ON a.id = b.parent_id GROUP BY a.id;