sql查询问题

huqin_1223 2008-02-20 02:40:27
有两张表:product和picture
product 中的字段:id....
picture 中的字段:id,proID(产品表中的id),url
一个产品对应几张图片,
现在要查询中一个产品对应的一张图片要如何实现???
...全文
83 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fjzz110 2008-02-20
  • 打赏
  • 举报
回复
拉完请冲水
老宛 2008-02-20
  • 打赏
  • 举报
回复
select   a.*,b.url   from   product   a  left join (select   proID,min(url)   as   url   from   picture   group   by   proId)   b   on   a.id=b.ProID
老宛 2008-02-20
  • 打赏
  • 举报
回复
select a.*,b.url from product a (select proID,min(url) as url from picture group by proId) b on a.id=b.ProID
pt1314917 2008-02-20
  • 打赏
  • 举报
回复
product 中的字段:id....
picture 中的字段:id,proID(产品表中的id),url
一个产品对应几张图片,
现在要查询中一个产品对应的一张图片要如何实现???



select a.*,b.url from product a,picture b
where a.id=b.proid and not exists(select 1 from picture where proid=b.proid and id>b.id)
冷箫轻笛 2008-02-20
  • 打赏
  • 举报
回复

--选择每个产品id最小的图片
select * from picture a
where not exists(select 1 from picture where proid = a.proid and id < a.id)

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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