Comments - Recursive Common Table Expressions Overview

5 years, 11 months ago Mike Reiche
This comment has the status of 'removed' and can only be seen by you.

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.

 
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.