product表id productnameproduct图片表id productid imageinfo
product表的id与product图片表的productid关联。一对多。
现在我要查去所有product然后每个条product记录带出product图片表中的一条信息出来。
product表的id与product图片表的productid关联。一对多。
现在我要查去所有product然后每个条product记录带出product图片表中的一条信息出来。
from product表 a inner join product图片表 b on a.id=b.productid
group by a.id,a.productname
from product表 a cross apply(select top(1)* from product图片表 b where a.id=b.productid order by newid())b
left join product图片表 b on a.id=b.productid
group by a.id
inner join product图片表 b on a.id=b.productid
where not exists(select 1 from product图片表 where a.id=productid and id>b.id)