SELECT a.content, a.postdate, c.username
FROM (
表1 a
INNER JOIN 表2 b ON a.uid = b.uid
)
INNER JOIN 表3 c ON a.uid = c.uid
ORDER BY username, postdate DESC 
LIMIT 50表1表2表三通过用户的uid关联如果想取得每一个用户的前2条表1记录,怎么取得啊

解决方案 »

  1.   

    select *
    from tb A
    where (select count(*) from tb where A.username=b.username and A.id>b.id)>2
      

  2.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    select *
    from tb A
    where (select count(*) from tb b where A.username=b.username and A.id>b.id)<2
      

  4.   

    SELECT a.content, a.postdate, c.username
    FROM 表1 a INNER JOIN 表2 b ON a.uid = b.uid
    INNER JOIN 表3 c ON a.uid = c.uid
    where 2>(select count(*) from 表1 where uid=a.uid and postdate>a.postdate)
    ORDER BY username, postdate DESC  
    LIMIT 50