HI KINDLY TRY THE BELOW ONE. YOU WILL GET IDEA.LET ME KNOW THAT, DO YOU NEED ANY FURTHER CLARIFFICATION Declare @t1 table (disease varchar(5) not null,symptom varchar(5) not null)Declare @t2 table (symptom varchar(5) not null)insert into @t1select 'A','X' unionselect 'A','Y' unionselect 'B','X' unionselect 'B','Y' unionselect 'C','X' unionselect 'C','Y' unionselect 'D','X'insert into @t2select 'X' unionselect 'Y';with cteas(Select a.Disease,b.Symptom,row_number() over(partition by a.disease order by a.disease) rn from @t1 a Join @t2 bon a.Symptom=b.Symptom)select Disease from cte where rn=2
Suri