select * from t_temp where product in (select product from t_temp where title=1)

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/2285/2285830.xml?temp=.1570551/*--树形数据处理方案 树形数据的排序,新增,修改,复制,删除,数据完整性检查,汇总统计
    --邹建 2003.9--*/
      

  2.   

    declare @t_temp table(title int,product varchar(10))
    insert @t_temp values(1       ,'a')
    insert @t_temp values(1     ,  'b')
    insert @t_temp values(2      , 'a')
    insert @t_temp values(2    ,   'c')
    insert @t_temp values(3   ,    'c')
    insert @t_temp values(3  ,     'd')
    insert @t_temp values(4 ,      'd')
    insert @t_temp values(5,       'e')
    declare @你的参数 int
    set @你的参数=1declare @临时表 table(title int,product varchar(10))insert @临时表 select * from @t_temp where product in (select product from @t_temp where title=@你的参数)while exists(select 1 from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product))
      insert @临时表 select * from @t_temp a where (product in (select product from @临时表) or title in (select title from @临时表)) and not exists (select 1 from @临时表 where title=a.title and product=a.product)select * from @临时表