Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selection problem
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01516648
Message ID:
01516670
Views:
30
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform