i want to display #acc that has no child here result must be B,C,D,E but getting B,C,D only
create table #acc (mainid int,name nvarchar(20),subid int)
insert into #acc values(1,'A',0)
insert into #acc values(2,'B',1)
insert into #acc values(3,'C',1)
insert into #acc values(4,'D',1)
insert into #acc values(5,'E',0)
select A.name from #acc
A inner join #acc B
on
A.subid = B.mainid
drop table #acc