Comments - Recursive Common Table Expressions Overview
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
How to get the depth of the graph?
<code> WITH RECURSIVE graph as ( SELECT pr.*,@depth as depth FROM rcte_people_relationships pr WHERE source_id=3 UNION SELECT pr.*,(@depth:=@depth+1) as depth FROM rcte_people_relationships pr, graph WHERE graph.target_id=pr.source_id ) SELECT * FROM graph CROSS JOIN (SELECT @depth := 0) AS depth; </code>
Creates an infinite loop.