There is no recursion in my CTE SQL request

  • I have very simple table

    CTE_08312022_024543_1

    I want to receive table with i,id and text column like 67->304->303->302->301->300->299

    I don't understand What wrong in my CTE?

    WITH RECURSIVE

    CTE (CTE_i, CTE_Id, CTE_ParentID, CTE_ParentI, Arrow) AS

    (

    Select i, Id, NULL, NULL,'.' FROM DockerImage where ParentId =''

    UNION ALL

    Select DockerImage.I, DockerImage.Id, DockerImage.ParentId, CTE_i , CONCAT (CTE.Arrow, '->', DockerImage.I) FROM CTE

    join DockerImage on CTE_ParentId=DockerImage.id

    )

    SELECT * FROM CTE;

    Result of this SQL is wrong and I have no recursion.

    CTE_08312022_025237_1

     

     

    • This topic was modified 2 years, 2 months ago by  Alex1337.
  • I think your join is backwards. The initial select has blank ParentID, so the join needs to be from cte.id to DockerImage.ParentID.

    JOIN    DockerImage  ON CTE.CTE_id = DockerImage.Parentid
  • Thank you, its working !!!

    CTE_09032022_161915_1

     

    • This reply was modified 2 years, 2 months ago by  Alex1337.
    • This reply was modified 2 years, 2 months ago by  Alex1337.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply