Get all child ids of a parent

PHOTO EMBED

Tue Sep 14 2021 06:05:48 GMT+0000 (UTC)

Saved by @codeplay #mysql

SELECT 
  GROUP_CONCAT(lv SEPARATOR ',')
  #lv
FROM 
  (
    SELECT 
      @pv :=(
        SELECT 
          GROUP_CONCAT(cid SEPARATOR ',') 
        FROM 
          categories 
        WHERE 
          FIND_IN_SET(parent, @pv)
      ) AS lv 
    FROM 
      categories 
      JOIN (
        SELECT 
          @pv := 5
      ) tmp
  ) tmp2
content_copyCOPY