>>I believe you need to reverse the condition, e.g.
>>
>>;with cte as (select T.*, row_number() over (order by NewID()) as RandomRow
>>from Test T where not exists (select 1 from Test T2 where T.FamilyID = T2.PartnerID))
>>
>>select * from cte where RandomRow <=4
>>
>>The above is from the top of my head - and may be a bit slow.
>
>
>With such cross data (if you see Nicholas has the same IDs in BOTH fields) you wouldn't get any rows.
Good point.
I will need to think about it more - it's not very trivial.
If it's not broken, fix it until it is.
My Blog