Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selecting customers that follow a particular trend

Author  Topic 

velvettiger
Posting Yak Master

115 Posts

Posted - 2008-07-09 : 17:56:25
Hi,

Problem

In the below table:

donor receptor
1 -> 4
2 -> 5
4 -> 6


The above reads as follows...

Student 1 donates all of his/her money to Student 4
Student 2 donates all of his/her money to Student 5
Student 4 donates all of his/her money to Student 6

I would like to pull all of the ultimate donors from the above table. An ultimate donor is someone who is at all times a receptor and never a donor.

So in the above scenario Students 5 and 6 are ultimate donors. Does anyone have any ideas on how this can be accomplished?

I will be very appreciative of any inputs.

Thanks

singularity
Posting Yak Master

153 Posts

Posted - 2008-07-09 : 19:13:43
select distinct receptor
from yourtable a
left join (select donor from yourtable) b on a.receptor = b.donor
where b.donor is null
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-10 : 01:07:15
select distinct receptor
from yourtable where receptor
not in (select donor from yourtable)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-10 : 01:11:14
quote:
An ultimate donor is someone who is at all times a receptor and never a donor





KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

velvettiger
Posting Yak Master

115 Posts

Posted - 2008-07-10 : 07:09:29
Oh an ultimate recpetor is someone who is at all time a receptor and never a donor
My bad...
Go to Top of Page
   

- Advertisement -