Example Database

id master_id ref_id
1 p1 c1
2 p2 c1
3 c1 c3
4 c3 c1
5 p3 c4
6 p3 c5

Starting with "p1" I wish to return the recursive list of master_id:ref_id

Here's the problem:
p1:c1
c1:c3
c3:c1 (circular reference)
c1:c3
.....
.....
etc

How do I overcome the circular reference using sql (T-SQL or CTE recursion)

I am a little confused. I am assuming that the ref_id is a uniqueid from another table?

I am a little confused. I am assuming that the ref_id is a uniqueid from another table?

First - tx for the response.
ref_id is just a text column like master_id. The column id is the primary key. The table stands alone with no references to other tables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.