Skip to content
Advertisement

How to get the third level of a tree in SQL

I aim to list the forth generation of a family using SQL Server.

Example family tree in the picture (id based)

FAMILY TREE

The tables I have are:

Family

Relations

This is the result I need:

Advertisement

Answer

You need to do the same join with different aliases to get the last generation The other option is to make recursive CTE.

The script used is:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement