access去除重复记录,在线等,谢谢了

cg20 2010-01-11 03:29:21
表products
表xl
现在我想读取xl里面的10条记录,但是xl_id要等于products表里的p_xlid,并且p_xlid只取products里面的以p_browsecount DESC排序的前10条
我用的这个取出来有重复记录
SELECT TOP 10 xl_info.xl_id,xl_info.xl_name FROM products,xl_info WHERE (xl_info.xl_id=products.p_xlid) ORDER BY products.p_browsecount DESC
...全文
736 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cg20 2010-01-13
  • 打赏
  • 举报
回复
distinct
ORDER BY 子句与 (products.p_browsecount) DISTINCT 冲突
  • 打赏
  • 举报
回复
distinct
aellonxie 2010-01-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wiki14 的回复:]
select  *  from  表名  where  name  in  (select  name  from  表名  having  count(name)>1)

[/Quote]

先取不重复的记录条数,然后select * from (不重复的记录ID) where ID in (不重复的记录ID)

cg20 2010-01-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wiki14 的回复:]
SQL codeselectTOP10 xl_info.xl_id,xl_info.xl_nameFROM xl_infowhere xl_info.xl_idin (select products.p_xlidfrom productsgroupby products.p_xlidhavingcount(products.p_xlid)>1)

用group  by  having
[/Quote]

还要将结果按照xl_taxis DESC显示,最后显示还是11条 ORDER BY xl_taxis DESC
chenguang79 2010-01-11
  • 打赏
  • 举报
回复
SELECT xl_info.xl_id,xl_info.xl_name FROM xl_info WHERE xl_id in (
SELECT distinct TOP 10 products.p_xlid FROM products,xl_info WHERE (xl_info.xl_id=products.p_xlid) ORDER BY products.p_browsecount DESC
)

试一下
cg20 2010-01-11
  • 打赏
  • 举报
回复
wiki14

SELECT TOP 10 xl_id,xl_name FROM xl_info WHERE (xl_id in (SELECT TOP 10 p_xlid FROM products ORDER BY p_browsecount DESC)) ORDER BY xl_taxis DESC
读出来只有9条记录
wiki14 2010-01-11
  • 打赏
  • 举报
回复

select TOP 10 xl_info.xl_id,xl_info.xl_name FROM xl_info
where xl_info.xl_id in (select products.p_xlid from products group by products.p_xlid having count(products.p_xlid) > 1)


用group by having
月之点点 2010-01-11
  • 打赏
  • 举报
回复

select top 10 b.xl_id,b.xl_name
FROM products as a inner JOIN xl_info as b
ON b.xl_id=a.p_xlid ORDER BY a.p_browsecount DESC

-.-!这个。。
月之点点 2010-01-11
  • 打赏
  • 举报
回复
用内连接啊!!!用内连接就没有重复的了

select top 10 b.xl_id,b.xl_name
FROM products as a inner JOIN xl_info as b
ON b.xl_id=a.p_xlid) ORDER BY a.p_browsecount DESC

-.-!
cg20 2010-01-11
  • 打赏
  • 举报
回复
异常详细信息: System.Data.OleDb.OleDbException: ORDER BY 子句与 (products.p_browsecount) DISTINCT 冲突。
hanzhaoever 2010-01-11
  • 打赏
  • 举报
回复
加关键字 distinct
wiki14 2010-01-11
  • 打赏
  • 举报
回复
select * from 表名 where name in (select name from 表名 having count(name)>1)
liudingguoo87 2010-01-11
  • 打赏
  • 举报
回复
SELECT distinct TOP 10 xl_info.xl_id,xl_info.xl_name FROM products,xl_info WHERE (xl_info.xl_id=products.p_xlid) ORDER BY products.p_browsecount DESC

62,254

社区成员

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

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

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

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