Skip to content

Instantly share code, notes, and snippets.

Created Jan 17, 2011
What would you like to do?
WITH RECURSIVE descendants(id, active, name, longname, parent_id, reseller, created_at, updated_at, uuid) AS (
SELECT * FROM client WHERE {conditions...}
SELECT client.* FROM client, descendants WHERE client.parent_id =
SELECT * FROM descendants
-- OR --
SELECT * FROM clients WHERE id IN (
WITH RECURSIVE descendants(id, parent_id) AS (
SELECT id, parent_id FROM clients WHERE {conditions...}
SELECT, clients.parent_id FROM clients, descendants WHERE clients.parent_id =
SELECT id FROM descendants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment