not sure what you wantdeclare @test1 table(chrom int,start int,[end] int,name varchar(10),score decimal(10,4),strand char(1))declare @test2 table(chrom int,start int,[end] int,name varchar(10),score decimal(10,4),strand char(1))insert into @test1select 11, 9720685, 9720721, 'U0', 0, '+' union allselect 21 , 9721043, 9721079 ,'U0' ,0 ,'-' union allselect 1 ,9721093, 9721129 ,'U0' ,0 ,'+' union allselect 20 , 9721485, 9721521, 'U0' , 0 , '+' union allselect 22 , 9721863, 9721899 ,'U0' , 0 , '-' union allselect 21 , 9721863, 9721899 ,'U0' , 0 , '-' union allselect 21 , 9721871, 9721907 ,'U0' , 0 , '-' union allselect 21 , 9721872, 9721908, 'U0' , 0 , '+' union allselect 5 ,9722423, 9722459 ,'U0' ,0 ,'+' union allselect 4 ,9722434, 9722470 ,'U0' ,0 ,'+'insert into @test2select 21, 9719765, 9749365, 'DOM1158', 61.7441 ,'+' union allselect 21, 10056465, 10211865 , 'DOM1159', 321.867, '+' union allselect 1, 31678598, 31859898, 'DOM1160', 73.8664, '+' union allselect 21, 32133698, 32300198 , 'DOM1161', 152.658, '+' union allselect 3, 32599898, 32910698, 'DOM1162', 435.853, '+' union allselect 21, 33177098, 33447198, 'DOM1163', 326.637, '+' union allselect 2, 33669198, 33728398, 'DOM1164', 46.8648, '+' union allselect 21, 33824598, 34013298, 'DOM1165', 116.821 ,'+' union allselect 20, 34120598, 34246398, 'DOM1166', 197.878, '+' union allselect 20, 34412898, 34505398, 'DOM1167' ,98.2537, '+'--soln 1select t1.chrom,count(*)from @test1 t1join @test2 t2on t1.chrom=t2.chromwhere t1.start>=t2.start and t1.[end] <= t2.[end]group by t1.chrom--soln2select t1.chrom,count(*)from @test1 t1join @test2 t2on t1.start>=t2.start and t1.[end] <= t2.[end]where t2.chrom=21group by t1.chromoutput------------------soln1-----------------chrom count21 4soln2--------------------chrom count1 14 15 111 120 121 422 1