i'm trying to implement a recursive query in MS SQL server 2008 using CTE. I know there are a lot of posts talking about recursion in SQL SERVER but this is a bit different and i'm getting stuck. I have a table with this structure:
CREATE TABLE [dbo].[Account](
[ID] [nvarchar](20) NULL,
[MAIN_EMAIL] [nvarchar](80) NULL,
[SECONDARY_EMAIL] [nvarchar](80) NULL)
This table represent a list of Account of course, these accounts can be duplicated in the table and i know they are if an account has a MAIN_EMAIL or a SECONDARY_EMAIL that exists in the MAIN_EMAIL or SECONDARY_EMAIL in another record with a different ID.
For example these records are duplicated in my table:

I know those records are duplicated because the ID 21206 has the main email that exists as main email in the record with ID 21246 and as secondary email in the record with ID 21268. Furthermore, the record with ID 21246 has a secondary email that exists as main email in the record with ID 28169. So, i consider those 4 records as a single record (this rule comes from project requirements).
Then, let's suppose i know the ID from which start this recursive query, suppose i know the first, with the ID 21206. I wrote this query but the result is a infinitive loop (and i get the error from MS SQL SERVER since it says i can do at maximum 100 recursions), if i select top 100 the result set contains the correct records, in this example the result is all ids 21206,21246,21268,28169 but these records are repeated to infinity, it seems the recursive part doesn't stop. The query is:
with cte (ID, MAIN_EMAIL, SECONDARY_EMAIL) as (
select ad.ID,ad.MAIN_EMAIL,ad.SECONDARY_EMAIL
from Account ad
where ad.ID = '21206'
union all
select ade.ID,ade.MAIN_EMAIL,ade.SECONDARY_EMAIL
from Account ade
inner join cte c
on (
(ade.MAIN_EMAIL = c.MAIN_EMAIL
or ade.SECONDARY_EMAIL = c.MAIN_EMAIL
or ade.MAIN_EMAIL = c.SECONDARY_EMAIL
or ade.SECONDARY_EMAIL = c.SECONDARY_EMAIL)
and ade.ID <> c.ID
)
)
select top 100 * from cte
I extracted those 4 records that are related and changed the emails for privacy. So the result should be the 4 records above. The result I get is a recordset with those 4 records (so it is correct but the recursive query doesn't stop so I get those 4 records to infinity).
Could you help me? Thank you in advance