去掉重复数据,急...

peng19873 2011-05-30 05:38:51
如题

select distinct(p.product_id),i.ImagesPath from teapp as p,Base_ProductInfo_Images as i where p.Product_id=i.Product_Id

这样查询还是会有重复数据,如果去掉 i.ImagesPath 就没有重复数据了,可是我有必须要ImagesPath 这个字段,怎么改呢,谢谢
...全文
38 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
peng19873 2011-05-30
  • 打赏
  • 举报
回复
OK ,解决了,谢谢各位
jiemo587 2011-05-30
  • 打赏
  • 举报
回复

select p.product_id,max(i.ImagesPath)
from teapp p left join Base_ProductInfo_Images i on p.Product_id=i.Product_Id
group by product_id
--没有说怎么取一条,就随便吧

Zoezs 2011-05-30
  • 打赏
  • 举报
回复

select distinct(p.product_id,i.ImagesPath) from teapp as p,Base_ProductInfo_Images as i where p.Product_id=i.Product_Id

这样能得到p.product_id,i.ImagesPath 这2个字段不重复的数据。
快溜 2011-05-30
  • 打赏
  • 举报
回复
select p.product_id,max(i.ImagesPath) ImagesPath 
from teapp as p,Base_ProductInfo_Images as i
where p.Product_id=i.Product_Id group by product_id
Zoezs 2011-05-30
  • 打赏
  • 举报
回复

你是想怎么匹配? 你这样就等于没加distinct.
如果你只想要product_id那就去掉ImagesPath,如果你想得到分组数据的话就得用group by.

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧