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
  • 33,472
  • 8
  • 93
  • 117
maximus
  • 10,204
  • 25
  • 85
  • 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
  • thx a lot for your comment!!! – maximus Mar 04 '12 at 22:55

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
  • 33,472
  • 8
  • 93
  • 117
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
  • 22,769
  • 6
  • 52
  • 166