why it doesn't work.
You do not extract rows from the first query:
SELECT * FROM [SMD].[dbo].[ProposalFollowUp] WHERE ID NOT IN (SELECT ParentID FROM [SMD].[dbo].[ProposalFollowUp])
Due to the NULL values in the ParentID there becomes UNKNOWN for the predicate, so it returns nothing, you can avoid this using NOT EXISTS :
SELECT * FROM [SMD].[dbo].[ProposalFollowUp] WHERE NOT EXISTS (SELECT ParentID FROM [SMD].[dbo].[ProposalFollowUp])
Unlike all other predicates in sQL, NOT EXISTS works on two logic values TRUE and FALSE , because there are only two possibilities for the value: exists (ture) or false, there is no way to return UNKNOWN .
There is another workaround that will not get what you are looking for in your case, that is, excluding these NULL values using AND ParentID IS NOT NULL , but in your case you will not get the results you are looking for
source share