select * from 表 order by id desc limit 10

解决方案 »

  1.   

    楼上的语句明显不不对...注意,我要的是10个不同的classid里的最新记录
      

  2.   

    select * from table GROUP BY classid order by id desc limit 10
      

  3.   

    楼上的你也明显不对.你想想.按classid分组了,后面的 ordery id desc 肯定没用了.
      

  4.   

    按classid分组然后把分组后的数据order by id是取出最后十条。
    怎么就肯定没用了????
      

  5.   

    好像就这个sql已经让我拿过好几次分了~:)mysql 4.1 以上:select * from table 
    where classid, postdate in 
     ( select classid,max(postdate) from table group by classid )
    order by postdate desc 
    limit 10
      

  6.   

    上面少了括号:select * from table 
    where (classid, postdate) in 
     ( select classid,max(postdate) from table group by classid )
    order by postdate desc 
    limit 10
      

  7.   

    看了楼上的查询才知道,原来mysql4.1以上就支持子查询了-_-||
      

  8.   

    如果你的ID是自增型的,上面的方法也可以;如果不是自增型的至少你的表里应该有时间字段吧??假设时间字段为dateline,可以像下面这样写.
    SELECT * 
    FROM `tt` 
    GROUP BY classid
    ORDER BY dateline DESC 
    LIMIT 0 , 10
      

  9.   

    我的MYSQL是不支持子查询的.所以,请问有别的办法吗
      

  10.   

    上面我的方法有问题,可能这样更好一些。SELECT DISTINCT * FROM (SELECT * FROM `tt` ORDER BY dateline DESC ) AS `t`
    GROUP BY classid
    ORDER BY dateline DESC 
    LIMIT 0 , 10
      

  11.   

    不支持?
    那我劝你还是用程序去控制吧.....
    先把纪录按时间排序查出来,然后程序按classid遍历一次,滤掉classid重复的行.
      

  12.   

    我的MYSQL是不支持子查询的.所以,请问有别的办法吗---------------------------- 不支持的话,一条sql不行