不太清楚你的数据结构,思路大慨是这样的.select a.*,b.商品信息 from(
select 合同编号,min(商品编号) as 商品编号 from incont group by 合同编号) a
,incom b where a.商品编号=b.商品编号

解决方案 »

  1.   

    select contno,cstname,(select top 1 spec from incom as b where b.contno=a.contno) as spec from incont as a
      

  2.   

    做一个视图,然后去选取就方面多了
    你可以按照contno,去找第一个商品了
      

  3.   

    select incont.contno,incom.spec,incont.cstname from (select * from incont tem where 主键=(select top 1 主键 from incont where contno=tem.contno)) incont,incom where incont.contno=incom.contno
      

  4.   

    select contno,(select top 1 spec from incom where contno=a.contno) as spec,cstnamefrom incont as a
    好象这样也行的,把b去掉,你试一下吧,速度还是可以的,应该不会比join查询慢。
      

  5.   

    select a.*,b.商品信息 from(
    select 合同编号,min(商品编号) as 商品编号 from incont group by 合同编号) a
    ,incom b where a.商品编号=b.商品编号
      

  6.   

    select * from incont a 
    left join (select * from incom aa where not exists( select 1 from incom bb where aa.任一唯一字段>bb.任一唯一字段)b
    on a.contno=b.contno