一条多表查询SQL语句

charmjs 2008-10-08 11:27:58
DataSet ds = Reader.ReturnDataSet("select smalltype,pic1,id from product where smalltype in(select smalltype from type where bigtype='" + Request.QueryString["type"] + "')");

我这条SQL语句想过滤smalltype重复的记录
意思就是一个小类只显示出一条记录
但是
DataSet ds = Reader.ReturnDataSet("select distinct smalltype,pic1,id from product where smalltype in(select smalltype from type where bigtype='" + Request.QueryString["type"] + "')");
似乎不管用.

请问有什么办法解决?
详细代码
public void ReaderImg()
{
data Reader = new data();
DataSet ds = Reader.ReturnDataSet("select smalltype,pic1,id from product where smalltype in(select smalltype from type where bigtype='" + Request.QueryString["type"] + "')");

for (i = 0; i < Convert.ToInt32(ds.Tables[0].Rows.Count.ToString()); i++)
{

hang[i]=ds.Tables[0].Rows[i][1].ToString();
}

}
...全文
109 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chtsir 2008-10-08
  • 打赏
  • 举报
回复
DataSet ds = Reader.ReturnDataSet("select smalltype,pic1,id from product where smalltype in(select smalltype from type where bigtype='" + Request.QueryString["type"] + "')");


以前的不修改,然后把select distinct * from( **************) 写在最外层试下吧!
********是以前的语句.
ashou706 2008-10-08
  • 打赏
  • 举报
回复
你的,pic1,id 这两个字段的内容肯定是重复的。
你应当先找到所有smalltype不重复的数据,之后在以 left join 的形式找到这些记录为基础的相应的pic1,id 数据。
charmjs 2008-10-08
  • 打赏
  • 举报
回复
虽然没怎么看懂.但是楼上的是对的。
BernardSun 2008-10-08
  • 打赏
  • 举报
回复

select smalltype,pic1,id from product a where id=(select min(id) from product left join type on product.smalltype=type.smalltype
where product.smalltype=a.smalltype and bigtype='" + Request.QueryString["type"] + "')

不知道你表结构,猜着写的
zhangqiaoqiao 2008-10-08
  • 打赏
  • 举报
回复
学习
greatverve 2008-10-08
  • 打赏
  • 举报
回复
学习.

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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