Is it possible to somehow ignore duplicate values ​​in recursion (CTE), otherwise it just loops?
There is a situation that during recursion there will be a looping:
For example:

id from_user to_user message 1 1 3 some msg 2 3 2 some msg 3 2 4 some msg 4 4 1 some msg 

I want to go through recursion to take all 4 records

  id from_user to_user message 1 1 3 some msg 2 3 2 some msg 3 2 4 some msg 4 4 1 some msg 

but that the record with id 1 (repetitive) does not enter recursion more than once, otherwise an infinite loop is obtained (up to OPTION (MAXRECURSION 100) times) ...
I need to take these records hierarchically ...

    1 answer 1

    Little is clear. Where is the request? What should recursion do?

    By the way, the default is a maximum of 100 iterations. If you do not use endless recursion, then looping does not threaten you.

    • Updated, wrote more details ... - Acne
    • one
      I see two identical tables. What is given to you and what is required to receive Better by example than words. - msi
    • I need to get these 4 records well, since in the last record, to_user refers again to the first one, it turns out to be an infinite loop ... the question is to pull out these 4 records by losing the second pass .... - Acne
    • 2
      Watch for id, for example, so that it does not decrease. - msi
    • I didn’t even think about it!) - Acne