Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL查询:从两个表中获取产品数据_Sql Server_Sql Server 2008 - Fatal编程技术网

Sql server SQL查询:从两个表中获取产品数据

Sql server SQL查询:从两个表中获取产品数据,sql-server,sql-server-2008,Sql Server,Sql Server 2008,我在SQL Server中有两个表。首先是product,另一个是Productimage 在ProductImage中,一个产品可以有多个图像 现在我想要所有产品,每个产品只有一张图片。所以请帮我写这样的查询 select p.prodid,max(i.image) from product p inner join Productimage i on p.prodid=i.prodid group by p.prodid 或 Plz根据您希望为产品从多个映像中选择一个映像,提供您的架构详

我在SQL Server中有两个表。首先是
product
,另一个是
Productimage

ProductImage
中,一个产品可以有多个图像

现在我想要所有产品,每个产品只有一张图片。所以请帮我写这样的查询

select p.prodid,max(i.image) from product p inner join Productimage i
on p.prodid=i.prodid
group by p.prodid 


Plz根据您希望为产品从多个映像中选择一个映像,提供您的架构详细信息和逻辑。您将如何为产品选择映像?选择TBLPProductMaster。*,tblCategoryMaster.CategoryName来自tblProductMaster内部加入tblProductMaster.CategoryID=tblCategoryMaster.CategoryID现在我想从TBLIMAGE添加imageName请不要将代码示例或示例数据放入注释中-因为您无法格式化它,所以读取它非常困难。。。。取而代之的是:通过编辑你的问题来更新它,以提供额外的信息!谢谢。@anand:-您是如何确定图像列的数据类型的?II已更新查询,请检查。首先,我认为图像列将具有图像文件的路径。选择TBLPProductMaster.*,tblCategoryMaster.CategoryName,MAX(TBLIManageMaster.ImageName)从TBLPProductMaster上的TBLPProductMaster内部连接tblCategoryMaster.CategoryID=tblCategoryMaster.CategoryID内部连接TBLIManageMaster上的TBLIManageMaster.ProductID=TBLPProductMaster.ProductID组由TBLPProductMaster.ProductIDi还使用连接添加类别名称并写入上面的查询bt,这给了我错误
select prodid,image from (
select p.prodid,i.image,row_number() over (order by p.prodid partition by p.prodid) as rn 
from product p inner join Productimage i
on p.prodid=i.prodid) a where a.rn=1