不太清楚你的数据结构,思路大慨是这样的.select a.*,b.商品信息 from(
select 合同编号,min(商品编号) as 商品编号 from incont group by 合同编号) a
,incom b where a.商品编号=b.商品编号
select 合同编号,min(商品编号) as 商品编号 from incont group by 合同编号) a
,incom b where a.商品编号=b.商品编号
你可以按照contno,去找第一个商品了
好象这样也行的,把b去掉,你试一下吧,速度还是可以的,应该不会比join查询慢。
select 合同编号,min(商品编号) as 商品编号 from incont group by 合同编号) a
,incom b where a.商品编号=b.商品编号
left join (select * from incom aa where not exists( select 1 from incom bb where aa.任一唯一字段>bb.任一唯一字段)b
on a.contno=b.contno