Skip to content
Advertisement

SQL Join table to itself

I have a table where there are two columns like below.

Basically, what it is saying is 1 was new, 2 was derived from 1, 3 was derived from 2 and so on.

I want the out put with 1 as the master key and 2,3,4 and 5 as children.

Is it achiveble in SQL ? Thanks in advance

Advertisement

Answer

As mentioned in the comment, the simplest way is with an rCTE (recursive Common Table Expression):

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