Select Parent and Children With MySQL

后端 未结 3 1392
后悔当初
后悔当初 2020-12-16 18:05

I know this question comes up often, but today I can\'t find the answer I\'m looking for. I have a table with this schema.

CREATE TABLE `comments` (
    `id`         


        
3条回答
  •  温柔的废话
    2020-12-16 18:37

    Are you looking for

    SELECT p.id, child.*
    FROM comments p
    INNER JOIN comments child ON (child.parent_id = p.id)
    WHERE ....
    

    UPDATE
    Or LEFT JOIN if you want to see rows with no parents

提交回复
热议问题