Skip to content

Instantly share code, notes, and snippets.

@elw00d
Created August 12, 2014 09:43
Show Gist options
  • Save elw00d/11038f43e61195b37e5f to your computer and use it in GitHub Desktop.
Save elw00d/11038f43e61195b37e5f to your computer and use it in GitHub Desktop.
Recursive CTE SQL Server
with cte as (
select id, parentId, name from Category where id = 17
union all
select c.id, c.parentId, c.name from Category c
join cte on c.id = cte.parentId
) select * from cte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment