Created
January 17, 2011 21:28
-
-
Save paul/783520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE descendants(id, active, name, longname, parent_id, reseller, created_at, updated_at, uuid) AS ( | |
SELECT * FROM client WHERE {conditions...} | |
UNION | |
SELECT client.* FROM client, descendants WHERE client.parent_id = descendants.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...} | |
UNION | |
SELECT clients.id, clients.parent_id FROM clients, descendants WHERE clients.parent_id = descendants.id | |
) | |
SELECT id FROM descendants | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment