Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How to explain recursive CTE in as simple a manner as possible

How to explain recursive CTE in as simple a manner as possible

Scheduled Pinned Locked Moved The Lounge
tutoriallearningdatabasesql-servercom
28 Posts 8 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rahul_Biswas

    I wrote the answer there and I can prove it. :)

    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #6

    Go on then.

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    R 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      Go on then.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      R Offline
      R Offline
      Rahul_Biswas
      wrote on last edited by
      #7

      But if you don't mind, can you spare some time and tell me how the article is?

      OriginalGriffO 1 Reply Last reply
      0
      • R Rahul_Biswas

        But if you don't mind, can you spare some time and tell me how the article is?

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #8

        At the moment, you have a bigger problem - I'm starting to suspect that you didn't write the article. So if you don't prove it pretty quickly - and you say you can - then somebody (maybe me, maybe not) is going to start the "plagiarism process" which will very quickly get your account closed. Permanently.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        R 2 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          At the moment, you have a bigger problem - I'm starting to suspect that you didn't write the article. So if you don't prove it pretty quickly - and you say you can - then somebody (maybe me, maybe not) is going to start the "plagiarism process" which will very quickly get your account closed. Permanently.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          R Offline
          R Offline
          Rahul_Biswas
          wrote on last edited by
          #9

          Sigh! Check this How to explain T-SQL recursive CTE concept with a simple example - Quora[^].

          OriginalGriffO 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            At the moment, you have a bigger problem - I'm starting to suspect that you didn't write the article. So if you don't prove it pretty quickly - and you say you can - then somebody (maybe me, maybe not) is going to start the "plagiarism process" which will very quickly get your account closed. Permanently.

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            R Offline
            R Offline
            Rahul_Biswas
            wrote on last edited by
            #10

            Now I am not sure about whether one can be accused of plagiarizing from oneself. Self-plagiarizing, perhaps? :rolleyes: It is me who wrote that answer. But of course, a better platform for that kind of answer is CodeProject. Don't you think? Now please check the link. I am going to delete the thread from Quora again. I don't want same article posted multiple times in multiple places.

            M 1 Reply Last reply
            0
            • R Rahul_Biswas

              Sigh! Check this How to explain T-SQL recursive CTE concept with a simple example - Quora[^].

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #11

              That's all I needed. We take plagiarism very seriously here, and have a "no second chances" policy. So when your article appears elsewhere and is suspiciously deleted, I do start to suspect the worst! :laugh: You'd be amazed how many people think that "copy and paste" equals "I wrote this" ... :sigh:

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              R 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                That's all I needed. We take plagiarism very seriously here, and have a "no second chances" policy. So when your article appears elsewhere and is suspiciously deleted, I do start to suspect the worst! :laugh: You'd be amazed how many people think that "copy and paste" equals "I wrote this" ... :sigh:

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                R Offline
                R Offline
                Rahul_Biswas
                wrote on last edited by
                #12

                I am deleting that thread at Quora again, okay? :) And hey, it is okay. :) And of course, why should a freeloader be allowed to claim another person's hard work as his or her own? It is best to be vigilant against these kind of attempts. :) By the way, can I now request you to spare some time in reading my article and provide your thoughts? If you don't mind, that is.

                1 Reply Last reply
                0
                • R Rahul_Biswas

                  Hi CodeProject members, Greetings! After being a passive reader of CodeProject articles for so long a time, it feels great to be actively contributing something to this thriving and extremely helpful community. Recently, I decided to undertake the task of explaining some relatively complex concepts of T-SQL, SQL Server and MSBI, in an effort to give back something to the community I have been learning from for so long. My goal is to simplify the explanation and elucidation of the concepts as much as possible, at the expense of being annoyingly verbose if need be. ;P To this effect, I started with explanation of a recursive Common Table Expression in t-SQL. My article can be found at[^] http://www.codeproject.com/Articles/1139746/Recursive-CTE. Now this is my first attempt at explaining something in writing. I need feedback-, how have I fared overall, suggestions for improvement, possible topics for later etc. Thus, I am sincerely hoping, active community members would help me out in this regard. I have tried explaining the recursive CTE concept to the best of my ability here. But of course, often one's best is still lacking in some respects. Please come forth with your comments and feedback. Could I have used a better example to explain the concept? Could I have used better formatting for the code snippets? Or the result-sets? How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept? Looking forward to hearing from you.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #13

                  So you really are desperate; posting this in three different forums is really bad form. All you are doing is cluttering the forums with unnecessary messages and getting a bad reputation for yourself. Which means quite a few people will not bother to read your article.

                  1 Reply Last reply
                  0
                  • R Rahul_Biswas

                    Hi CodeProject members, Greetings! After being a passive reader of CodeProject articles for so long a time, it feels great to be actively contributing something to this thriving and extremely helpful community. Recently, I decided to undertake the task of explaining some relatively complex concepts of T-SQL, SQL Server and MSBI, in an effort to give back something to the community I have been learning from for so long. My goal is to simplify the explanation and elucidation of the concepts as much as possible, at the expense of being annoyingly verbose if need be. ;P To this effect, I started with explanation of a recursive Common Table Expression in t-SQL. My article can be found at[^] http://www.codeproject.com/Articles/1139746/Recursive-CTE. Now this is my first attempt at explaining something in writing. I need feedback-, how have I fared overall, suggestions for improvement, possible topics for later etc. Thus, I am sincerely hoping, active community members would help me out in this regard. I have tried explaining the recursive CTE concept to the best of my ability here. But of course, often one's best is still lacking in some respects. Please come forth with your comments and feedback. Could I have used a better example to explain the concept? Could I have used better formatting for the code snippets? Or the result-sets? How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept? Looking forward to hearing from you.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #14

                    Sorry I can't help as I know nothing on T-SQL or SQL Server in the last 15 years. But to everyone else, just fuck off and look at his article and judge him on that. The posting in 3 forums has been addressed in his initial or second reply. Get a life you miserable cunts and whinge like bitches else where.

                    Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                    R R 2 Replies Last reply
                    0
                    • L Lost User

                      Sorry I can't help as I know nothing on T-SQL or SQL Server in the last 15 years. But to everyone else, just fuck off and look at his article and judge him on that. The posting in 3 forums has been addressed in his initial or second reply. Get a life you miserable cunts and whinge like bitches else where.

                      Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                      R Offline
                      R Offline
                      Rahul_Biswas
                      wrote on last edited by
                      #15

                      Thanks Martin! :) I owe you.

                      M 1 Reply Last reply
                      0
                      • R Rahul_Biswas

                        Hi CodeProject members, Greetings! After being a passive reader of CodeProject articles for so long a time, it feels great to be actively contributing something to this thriving and extremely helpful community. Recently, I decided to undertake the task of explaining some relatively complex concepts of T-SQL, SQL Server and MSBI, in an effort to give back something to the community I have been learning from for so long. My goal is to simplify the explanation and elucidation of the concepts as much as possible, at the expense of being annoyingly verbose if need be. ;P To this effect, I started with explanation of a recursive Common Table Expression in t-SQL. My article can be found at[^] http://www.codeproject.com/Articles/1139746/Recursive-CTE. Now this is my first attempt at explaining something in writing. I need feedback-, how have I fared overall, suggestions for improvement, possible topics for later etc. Thus, I am sincerely hoping, active community members would help me out in this regard. I have tried explaining the recursive CTE concept to the best of my ability here. But of course, often one's best is still lacking in some respects. Please come forth with your comments and feedback. Could I have used a better example to explain the concept? Could I have used better formatting for the code snippets? Or the result-sets? How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept? Looking forward to hearing from you.

                        B Offline
                        B Offline
                        Besinger
                        wrote on last edited by
                        #16

                        I actually found it helpful in creating a stored procedure for a report. Unfortunately I couldn't use a CTE due to some other constraints, but I did learn something. Thanx!

                        R 1 Reply Last reply
                        0
                        • B Besinger

                          I actually found it helpful in creating a stored procedure for a report. Unfortunately I couldn't use a CTE due to some other constraints, but I did learn something. Thanx!

                          R Offline
                          R Offline
                          Rahul_Biswas
                          wrote on last edited by
                          #17

                          Great that you found it useful, Besinger! :) If you would like to talk about why you cannot use CTE in your SP, I would be glad to help.

                          1 Reply Last reply
                          0
                          • R Rahul_Biswas

                            Hi CodeProject members, Greetings! After being a passive reader of CodeProject articles for so long a time, it feels great to be actively contributing something to this thriving and extremely helpful community. Recently, I decided to undertake the task of explaining some relatively complex concepts of T-SQL, SQL Server and MSBI, in an effort to give back something to the community I have been learning from for so long. My goal is to simplify the explanation and elucidation of the concepts as much as possible, at the expense of being annoyingly verbose if need be. ;P To this effect, I started with explanation of a recursive Common Table Expression in t-SQL. My article can be found at[^] http://www.codeproject.com/Articles/1139746/Recursive-CTE. Now this is my first attempt at explaining something in writing. I need feedback-, how have I fared overall, suggestions for improvement, possible topics for later etc. Thus, I am sincerely hoping, active community members would help me out in this regard. I have tried explaining the recursive CTE concept to the best of my ability here. But of course, often one's best is still lacking in some respects. Please come forth with your comments and feedback. Could I have used a better example to explain the concept? Could I have used better formatting for the code snippets? Or the result-sets? How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept? Looking forward to hearing from you.

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #18

                            After reading the comments here (and Michael's was spot on, IMO), here's my thoughts: Nice example, though please fix the clickey. At this point, it seems to point to my last post! Explain: The ‘UNION ALL’ is a syntactic handcuff. What do you mean by "handcuff?" You might want to reference other explanations, like SQL Anywhere: Example: RECURSIVE UNION[^]

                            Rahul_Biswas wrote:

                            Could I have used better formatting for the code snippets?

                            IMO, yes -- get rid of the extra lines and use them only to separate top level "blocks" like "select" and "union"

                            Rahul_Biswas wrote:

                            Or the result-sets?

                            Yes - get rid of extra lines or use screenshots.

                            Rahul_Biswas wrote:

                            How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept?

                            That's a difficult question. Some suggestions: 1. a lot of people want to know about performance. Dig into the SQL plan so people get an idea if SQL Server is doing a full table scan, and if it is, are there ways to prevent that? 2. as silly as it sounds, explain what "recursive" actually means. 3. What are the alternatives? Can you remove the self-reference (requiring a nullable column) by splitting the table into employees and supervisors? (Why yes, you can.) What are the pros and cons of that architecture and how does it affect the query and performance? 4. How does this stuff work with an ORM, like EF? Is EF smart enough to use UNION ALL or does it do separate queries or does it bail and leave it up to the coder? [edit] You might want to illustrate (with #3 in mind) how you do other queries as well, like: 1. people that are supervisors but do not have supervisors. 2. people that are not supervisors but are themselves supervised. 3. immediate people that are being supervised by supervisors that do not have supervisors. 4. all people in the hierarchy that are being supervised by supervisors that do or do not have supervisors. 5. traverse the hierarchy upwards: given a person, who are all their supervisors, recursively. [/edit] Thinking of queries like that delve more

                            R 1 Reply Last reply
                            0
                            • M Marc Clifton

                              After reading the comments here (and Michael's was spot on, IMO), here's my thoughts: Nice example, though please fix the clickey. At this point, it seems to point to my last post! Explain: The ‘UNION ALL’ is a syntactic handcuff. What do you mean by "handcuff?" You might want to reference other explanations, like SQL Anywhere: Example: RECURSIVE UNION[^]

                              Rahul_Biswas wrote:

                              Could I have used better formatting for the code snippets?

                              IMO, yes -- get rid of the extra lines and use them only to separate top level "blocks" like "select" and "union"

                              Rahul_Biswas wrote:

                              Or the result-sets?

                              Yes - get rid of extra lines or use screenshots.

                              Rahul_Biswas wrote:

                              How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept?

                              That's a difficult question. Some suggestions: 1. a lot of people want to know about performance. Dig into the SQL plan so people get an idea if SQL Server is doing a full table scan, and if it is, are there ways to prevent that? 2. as silly as it sounds, explain what "recursive" actually means. 3. What are the alternatives? Can you remove the self-reference (requiring a nullable column) by splitting the table into employees and supervisors? (Why yes, you can.) What are the pros and cons of that architecture and how does it affect the query and performance? 4. How does this stuff work with an ORM, like EF? Is EF smart enough to use UNION ALL or does it do separate queries or does it bail and leave it up to the coder? [edit] You might want to illustrate (with #3 in mind) how you do other queries as well, like: 1. people that are supervisors but do not have supervisors. 2. people that are not supervisors but are themselves supervised. 3. immediate people that are being supervised by supervisors that do not have supervisors. 4. all people in the hierarchy that are being supervised by supervisors that do or do not have supervisors. 5. traverse the hierarchy upwards: given a person, who are all their supervisors, recursively. [/edit] Thinking of queries like that delve more

                              R Offline
                              R Offline
                              Rahul_Biswas
                              wrote on last edited by
                              #19

                              Thank you so very much. These are very helpful comments and suggestions. I will try to modify the article going forward with these. Once again, thanks so much.

                              1 Reply Last reply
                              0
                              • R Rahul_Biswas

                                Now I am not sure about whether one can be accused of plagiarizing from oneself. Self-plagiarizing, perhaps? :rolleyes: It is me who wrote that answer. But of course, a better platform for that kind of answer is CodeProject. Don't you think? Now please check the link. I am going to delete the thread from Quora again. I don't want same article posted multiple times in multiple places.

                                M Offline
                                M Offline
                                Mark_Wallace
                                wrote on last edited by
                                #20

                                Rahul_Biswas wrote:

                                Now I am not sure about whether one can be accused of plagiarizing from oneself.

                                I was, once, by a Dutch moron living in Kowloon and conning kids out of money for mostly copied-and-pasted English lessons (example here[^]) The stuff he added himself in the discussion boards he spammed was always completely wrong, so I was continually pulling him up on it (as well as posting the sources of his stolen text). On one occasion, I quoted my own text from one of my own sites, and he immediately flared up, demanding to know how I dared to call him a plagiarist and thief, when I had "stolen" the words from a web-site. Ranted about it for several hundred words. So I added a comment at the top of the page I'd copied my work out of, telling him in no uncertain terms precisely what kind of idiot he is. Dick W.J. Oosterveld, the guy's name. Pretends to be the CO of a non-existent company named HKEOL (started as Hong Kong Exporters On-line, a poorly made web-shop that never sold a bean, then changed to Hong Kong English On Line, when he realised he could bilk Chinese kids out of money for copied and pasted English lessons). If you ever run across him, give him a smack in the mouth from me.

                                I wanna be a eunuchs developer! Pass me a bread knife!

                                R 1 Reply Last reply
                                0
                                • R Rahul_Biswas

                                  Thanks Martin! :) I owe you.

                                  M Offline
                                  M Offline
                                  Mark_Wallace
                                  wrote on last edited by
                                  #21

                                  How much beer can you afford?

                                  I wanna be a eunuchs developer! Pass me a bread knife!

                                  1 Reply Last reply
                                  0
                                  • M Mark_Wallace

                                    Rahul_Biswas wrote:

                                    Now I am not sure about whether one can be accused of plagiarizing from oneself.

                                    I was, once, by a Dutch moron living in Kowloon and conning kids out of money for mostly copied-and-pasted English lessons (example here[^]) The stuff he added himself in the discussion boards he spammed was always completely wrong, so I was continually pulling him up on it (as well as posting the sources of his stolen text). On one occasion, I quoted my own text from one of my own sites, and he immediately flared up, demanding to know how I dared to call him a plagiarist and thief, when I had "stolen" the words from a web-site. Ranted about it for several hundred words. So I added a comment at the top of the page I'd copied my work out of, telling him in no uncertain terms precisely what kind of idiot he is. Dick W.J. Oosterveld, the guy's name. Pretends to be the CO of a non-existent company named HKEOL (started as Hong Kong Exporters On-line, a poorly made web-shop that never sold a bean, then changed to Hong Kong English On Line, when he realised he could bilk Chinese kids out of money for copied and pasted English lessons). If you ever run across him, give him a smack in the mouth from me.

                                    I wanna be a eunuchs developer! Pass me a bread knife!

                                    R Offline
                                    R Offline
                                    Rahul_Biswas
                                    wrote on last edited by
                                    #22

                                    :-D

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      Sorry I can't help as I know nothing on T-SQL or SQL Server in the last 15 years. But to everyone else, just fuck off and look at his article and judge him on that. The posting in 3 forums has been addressed in his initial or second reply. Get a life you miserable cunts and whinge like bitches else where.

                                      Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                                      R Offline
                                      R Offline
                                      Rajesh R Subramanian
                                      wrote on last edited by
                                      #23

                                      Absolutely! :thumbsup:

                                      1 Reply Last reply
                                      0
                                      • R Rahul_Biswas

                                        Hi CodeProject members, Greetings! After being a passive reader of CodeProject articles for so long a time, it feels great to be actively contributing something to this thriving and extremely helpful community. Recently, I decided to undertake the task of explaining some relatively complex concepts of T-SQL, SQL Server and MSBI, in an effort to give back something to the community I have been learning from for so long. My goal is to simplify the explanation and elucidation of the concepts as much as possible, at the expense of being annoyingly verbose if need be. ;P To this effect, I started with explanation of a recursive Common Table Expression in t-SQL. My article can be found at[^] http://www.codeproject.com/Articles/1139746/Recursive-CTE. Now this is my first attempt at explaining something in writing. I need feedback-, how have I fared overall, suggestions for improvement, possible topics for later etc. Thus, I am sincerely hoping, active community members would help me out in this regard. I have tried explaining the recursive CTE concept to the best of my ability here. But of course, often one's best is still lacking in some respects. Please come forth with your comments and feedback. Could I have used a better example to explain the concept? Could I have used better formatting for the code snippets? Or the result-sets? How could I have ensured that this article is as helpful as possible to a person who is finding it difficult to grasp the recursive CTE concept? Looking forward to hearing from you.

                                        K Offline
                                        K Offline
                                        kentgorrell
                                        wrote on last edited by
                                        #24

                                        Simple rule for training or instruction is - Tell them what you are going to tell them Tell them Tell them what you told them in other words - give an overview in simple point form here you should start with a paragraph that allows the reader to decide whether the content is relevant to them. After reading that paragraph they should be able to decide whether to read on or not. deliver the details Keep the paragraphs short. No more than a few sentences. This allows the reader to take bite size information. Nothing turns me off more than long paragraphs that I need to reread 3 times to get it. then recap with simple reminder, in point form, of what you told them. When I write I start with a list of things I want to talk about, rearrange the list so it gradually builds on the previous knowledge. This reinforces the previous while providing small steps. it's also good to use examples that the target audience can relate to. In this case it's developers so an example that uses Dilbert and his pointy headed boss would be appropriate. Hope this helps.

                                        R 1 Reply Last reply
                                        0
                                        • K kentgorrell

                                          Simple rule for training or instruction is - Tell them what you are going to tell them Tell them Tell them what you told them in other words - give an overview in simple point form here you should start with a paragraph that allows the reader to decide whether the content is relevant to them. After reading that paragraph they should be able to decide whether to read on or not. deliver the details Keep the paragraphs short. No more than a few sentences. This allows the reader to take bite size information. Nothing turns me off more than long paragraphs that I need to reread 3 times to get it. then recap with simple reminder, in point form, of what you told them. When I write I start with a list of things I want to talk about, rearrange the list so it gradually builds on the previous knowledge. This reinforces the previous while providing small steps. it's also good to use examples that the target audience can relate to. In this case it's developers so an example that uses Dilbert and his pointy headed boss would be appropriate. Hope this helps.

                                          R Offline
                                          R Offline
                                          Rahul_Biswas
                                          wrote on last edited by
                                          #25

                                          Thanks for the great suggestions. :) Can you elaborate a bit more on 'When I write I start with a list of things I want to talk about, rearrange the list so it gradually builds on the previous knowledge. This reinforces the previous while providing small steps.'? Thanks again.

                                          K 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups