Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
id parentId
1 null
2 1
3 2
4 3
5 1
8 2
10 3
Posted
Comments
OriginalGriff 11-Oct-12 3:54am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Naga KOTA 11-Oct-12 4:00am    
first try to explain the question clearly
vivektiwari97701 11-Oct-12 4:22am    
update your que. with youe code
Oshtri Deka 11-Oct-12 4:44am    
What the...?!?
Please improve your question. Here we have savants, but not seers.

Please use this SQL query to select all unique parent id


Select distinct(parentId) from tableName
 
Share this answer
 
SQL
DECLARE @FindParentsForMember INT;
SET  @FindParentsForMember = 757;
WITH Hierarchy(MemId,ParentId) 
AS(
     SELECT DISTINCT parent.MemId,parent.ParentId
     FROM Members parent
     WHERE parent.MemId = @FindParentsForMember
 
     UNION ALL
 
     SELECT child.MemId,child.ParentId
     FROM Members child
     INNER JOIN Hierarchy parent ON parent.ParentId = child.MemId
)
SELECT DISTINCT ParentId
FROM Hierarchy
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900