Try this . . . create table #WidgetTable( ID int, WidgetName varchar(50), WidgetPopularity int, WidgetType varchar(10))create table #temp( ID int, WidgetName varchar(50), WidgetPopularity int, WidgetType varchar(10))insert into #WidgetTable select 1 , 'RedWidget' , 8 , 'Useful' union all select 2 , 'BlueWidget' , 7 , 'Useful' union all select 3 , 'MyWidget' , 8 , 'Useless' union all select 4 , 'YourWidget' , 8 ,'Useless' union all select 5 , 'AnotherWidget' , 7 , 'Useless' union all select 6 , 'WickedWidget' , 7 , 'Helpful'create table #WidgetRelationshipTable( WidgetID int, RelatedID int)insert into #WidgetRelationshipTable select 3 , 4delete #tempinsert into #tempselect top 1 * from #WidgetTable where WidgetType = 'Useful' order by WidgetPopularity desc, IDinsert into #tempselect top 2 w.* from #WidgetTable w left join #WidgetRelationshipTable r on w.ID = r.RelatedID where WidgetType = 'Useless' and r.WidgetID is null order by WidgetPopularity desc, IDinsert into #tempselect top 1 * from #WidgetTable where WidgetType = 'Helpful' order by WidgetPopularity desc, IDselect * from #temp
-----------------'KH'if you can't beat them, have someone else to beat them