﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / Recursive Query / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 06:46:00 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Recursive Query</title><link>http://www.sqlservercentral.com/Forums/Topic1005053-392-1.aspx</link><description>[quote][b]sridharkannan7 (10/15/2010)[/b][hr]I've a table with data shown as belowDetailsID FollowupID1               02               03               14               25               3if you look at the above data, "3" is a followup of 1 and "5" is a followup of "3"Similarly "4" is a followup of "2"and 1 and 2 are original ids or parent ids.I've to write a query that will retrieve only the parent and the last child of that parent.I used recursion but that retrieves the entire chain. How do I further get only the parent and the last child[/quote]Considering the LOS that some folks gave you on this, allow me to ask... did you ever get an answer for this that worked for you?</description><pubDate>Sun, 24 Oct 2010 19:50:36 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Recursive Query</title><link>http://www.sqlservercentral.com/Forums/Topic1005053-392-1.aspx</link><description>Use a nested sets model, then look for leaf nodes. Your bad DDL will only lead to stinking bad DML.</description><pubDate>Fri, 15 Oct 2010 17:10:32 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: Recursive Query</title><link>http://www.sqlservercentral.com/Forums/Topic1005053-392-1.aspx</link><description>you can do this;[code="sql"];WITHcteFindMax AS( SELECT ROW_NUMBER() OVER (PARTITION BY DetailsID, FollowupID ORDER BY FollowupID DESC) AS Occurance,		*	FROM [the name of your table]) SELECT * FROM cteFindMax WHERE Occurance = 1[/code]</description><pubDate>Fri, 15 Oct 2010 06:54:00 GMT</pubDate><dc:creator>Geoff A</dc:creator></item><item><title>RE: Recursive Query</title><link>http://www.sqlservercentral.com/Forums/Topic1005053-392-1.aspx</link><description>Post what you've tried already. Can you set up some sample data? One of the links in my sig will show you how to do this.</description><pubDate>Fri, 15 Oct 2010 06:24:36 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>Recursive Query</title><link>http://www.sqlservercentral.com/Forums/Topic1005053-392-1.aspx</link><description>I've a table with data shown as belowDetailsID FollowupID1               02               03               14               25               3if you look at the above data, "3" is a followup of 1 and "5" is a followup of "3"Similarly "4" is a followup of "2"and 1 and 2 are original ids or parent ids.I've to write a query that will retrieve only the parent and the last child of that parent.I used recursion but that retrieves the entire chain. How do I further get only the parent and the last child</description><pubDate>Fri, 15 Oct 2010 05:07:47 GMT</pubDate><dc:creator>sridharkannan7</dc:creator></item></channel></rss>