select * from A inner join B on A.authorid = B.uid order by credits desc limit 0,10这是discuz里的数据调用
大家看下我的调用 A是主题表 B是会员表
我是想调用主题表和会员表这两个数据库,以主题表里的authorid(会员ID)和会员表的uid(会员ID)进行匹配,按会员表里的credits(总积分)进行排序.我想的结果是从高往下调用10条积分最高的会员和他们的最新的一条帖子,
但是实际的输出结果是出现:积分最高的一个会员和他的10条帖子!
请大家帮我下,该怎么写啊!我是新手!绝对菜鸟一枚!

解决方案 »

  1.   

    mysql 语法不太熟悉,应该基本上这样处理吧:
    select * from A t1 inner join B t2 on t1.authorid = t2.uid 
    where not exists(select 1 from A where authorid=t1.authorid where id>t1.id)
    order by credits desc limit 0,10 
      

  2.   

    select A.*
    from A  inner join (
    select  authorid,MAX(记录时间) as 记录时间 
    from A where authorid in (select uid from  B  order by credits desc limit  10)
    group by authorid) as b on a.authorid=b.authorid and a.记录时间=b.记录时间