forums   id   title             
   1   asjd;fkja
   2   askdjfl;asf
   3   asldkfja;sf
.............posts  id   fup   title   message  
   1    1     asd     lkasdjf;
   2    1    asdklfj  alksdjf;asdf
   3    1   lkasdf    aslkdfj;as
   4    3    asldkfj   alskdf;asf
   5    2   lkasdf    alskdfj;sdfj;
.....................

解决方案 »

  1.   

    select f.*,p.* from forums f,posts p where f.id=p.id order by p.id desc没有试,你看看行不行?
    ========================================
    IT圈的女程序员:http://www.66feifei.com
      

  2.   

    mysql现在还不支持limit用于子查询,有点难度。
    不过,原文的方法并非效率不高。
    如果实在想一次完成,也可以加一些字段来达到这个目的。
      

  3.   


    从手册的comment里找到一个例子,间接达到了从句用limit的功能,但是
    没想出来如何用到楼主的问题上,。楼主的问题更绕人一点
    http://dev.mysql.com/doc/mysql/en/row-subqueries.htmlIf you try the following you will find it fails in mysql version 4.1, SELECT 
    COUNT(*)
    FROM
    TABLE_1
    WHERE
    ROW (PK_PART_1, PK_PART_2) IN
    (
    SELECT 
    PK_PART_1, PK_PART_2
    FROM
    TABLE_2
    LIMIT 
    10 -- This is the basis of the whole idea
    )
    AND
    Whatever;The above fails with the warning ... ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'However, you can get the desired behaviour with a slight rewrite...SELECT 
    COUNT(*)
    FROM
    TABLE_1
    INNER JOIN
    (
    SELECT 
    PK_PART_1, PK_PART_2
    FROM
    TABLE_2
    LIMIT 
    10 -- HEY HEY!
    ) AS VIRTUAL_TABLE_2
    ON
    TABLE_1.PK_PART_1 = TABLE_2.PK_PART_1 AND
    TABLE_1.PK_PART_2 = TABLE_2.PK_PART_2
    WHERE
    Whatever;And it works like a charm!