Skip to content
Advertisement

Endless Loop or No Output for Recursive SQL Query

I have the following table,

My goal is to create a supervisor view in which there is a 4th column that has the name of the supervisor that matches the S code. My query returns to me either nothing except the column headers or a never ending recursion that loops into the 100,000’s.

What I’ve written is

Returns endlessly,

or

I’ve been trying to read about this and figure it out on my own but at this point I’ve struggled for long enough that I think I need it explained to me as to why it’s not working or how wildly wrong I’m going about this.

Advertisement

Answer

Please try the following solution. It is using self-join approach with two aliases for the same table: e(mployee) and s(upervisor).

SQL

Output

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