5

I am trying to understand sql recursive statements, but it is really hard for me. For example:

enter image description here

Thats an exampe I am trying to understand and to write down the output.

Can sb pls explain me how this works, step by step?

greetings and thx in advance

maya

devdigital
  • 34,151
  • 9
  • 98
  • 120
maximus
  • 11,264
  • 30
  • 93
  • 124
  • 3
    There is a highly detailed set of three examples here: http://walkingoncoals.blogspot.com/2009/12/fun-with-recursive-sql-part-1.html I also have [a blog post](http://adam-bernier.appspot.com/post/91001/recursive-sql-example) on the subject (specific to PostgreSQL). – mechanical_meat Mar 04 '12 at 22:43

2 Answers2

2

Also, see here - http://www.postgresql.org/docs/8.4/static/queries-with.html, where the steps of the recursive query evaluation are described.

devdigital
  • 34,151
  • 9
  • 98
  • 120
0

The UNION ALL portion gets recursed until it returns no more records. I don't know if you can have multiple UNION ALL portions.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182