product表id productnameproduct图片表id productid imageinfo
product表的id与product图片表的productid关联。一对多。
现在我要查去所有product然后每个条product记录带出product图片表中的一条信息出来。

解决方案 »

  1.   

    select a.id,a.productname,max(b.imageinfo)
    from product表 a inner join product图片表 b on a.id=b.productid
    group by a.id,a.productname
      

  2.   

    随便用了一个 max 函数,取一条出来,因为不知道楼主要取 product图片表 中的哪一条.
      

  3.   

    select a.id,a.productname,b.*
    from product表 a cross apply(select top(1)* from  product图片表 b where a.id=b.productid order by newid())b
      

  4.   

    select a.id,min(a.productname),min(b.imageinfo) from product表 a 
    left join product图片表 b on a.id=b.productid
    group by a.id
      

  5.   

    我product表里还有很多其它字段啊,都要带出来的。
      

  6.   

     select  * from product表 a 
     inner join product图片表 b on a.id=b.productid
     where not exists(select 1 from product图片表 where a.id=productid and id>b.id)