Can anybody help me out how to find the orphaned value from the below parent/child hierarchy Table.create table dbo.Hier(parent varchar(100), child varchar(100))insert into Hierselect 'subramanium','Manickam' union allselect 'subramanium','Munuswamy' union allselect 'Munuswamy','senthil' union allselect 'Munuswamy','sasi' union allselect 'Munuswamy','uma' union allselect 'manickam','vijay' union allselect 'manickam','bhavani' union allselect 'manickam','dhanam' union allselect 'uma','varsha'Delete from Hier where child='uma'
I tried:select parent from Hier where parent not in(select Child from Hier) and parent <> 'subramanium'
Getting resultset as:parent======uma
I need to know whether my select statement is correct or not,if its correct,how to write the same in CTE?