当前位置: 代码迷 >> ASP.NET >> 一句不算太难的sql语句,麻烦了。解决办法
  详细解决方案

一句不算太难的sql语句,麻烦了。解决办法

热度:5442   发布时间:2013-02-26 00:00:00.0
一句不算太难的sql语句,麻烦了。
有两个表   member和info
info表中有membeid和member关联。

会员可以发布信息到info表,     现在怎么能得到最新的10个发布了信息的会员名称membername,并且不重复?
我是这样写的,select   membername   from   member   where   memberid   in(select   top   10   distinct   memberid   from   info   order   by   infoid   desc)     但是报错了。

top   和   distinct该怎么用?

------解决方案--------------------------------------------------------
select distinct top 10 memberid from info order by infoid desc
------解决方案--------------------------------------------------------
select top 10 distinct 写反了
------解决方案--------------------------------------------------------
select membername from member where memberid in(select top 10 distinct memberid,infoid from info order by infoid desc
------解决方案--------------------------------------------------------
這樣呢?

select membername from member where memberid in(select distinct top 10 memberid from info order by infoid desc)


------解决方案--------------------------------------------------------
帮定
------解决方案--------------------------------------------------------
select membername from member where memberid in(select top 10 memberid,max(infoid) as newid from info group by memberid order by newid desc)
------解决方案--------------------------------------------------------
try

select membername from member where memberid in(select top 10 memberid from info Group By memberid order by Max(infoid) desc)
  相关解决方案