SQL: CTE Parent-child recursive

PHOTO EMBED

Mon Aug 29 2022 18:08:13 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #sql

WITH RECURSIVE PADRE AS (
	SELECT
		COD_CTA,
		DES_CTA
	FROM
		CATALOGO
	WHERE
		COD_CTA=:COD_CTA
	UNION ALL
		SELECT
			e.COD_CTA,
			e.DES_CTA
		FROM
			CATALOGO e
		INNER JOIN padre p ON POSITION(e.COD_CTA, p.COD_CTA) = 1
		  AND p.COD_CTA > COD_CTA
		ROWS 1
) SELECT
	DISTINCT cod_cta
FROM
	PADRE
WHERE COD_CTA < :COD_CTA
content_copyCOPY

Finds all parents of specific accounts in accounting table.