Imagine a table like below:
Table : Person
Fields: ID, FullName, ParentID
Where ParentID references an ID in Person table again.
Question:
For the example given above, how can I query in TSQL to find the toppest Parent of the Person with ID = 7 ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You would use common table expressions and do a recursive query until you find the topmost parent like so: