以title或者 id  来判断(保留时间较晚的数据)原表:test_main
title    date                 name     id
吃饭     2013-4-6 16:20:39      张三     0001
吃饭     2013-4-6 15:20:39      李四     0001
喝水     2013-4-6 11:20:39      王五     0003
喝水     2013-4-6 16:20:39      赵六     0003
睡觉     2013-4-6 19:20:39      赵六     0008结果:
title    date                  name      id
吃饭     2013-4-6 16:20:39      张三     0001
喝水     2013-4-6 16:20:39      赵六     0003
睡觉     2013-4-6 19:20:39      赵六     0008

解决方案 »

  1.   

    select * from tb a where not exists (select 1 from tb b where a.id=b.id and a.date>b.date)
      

  2.   

    select * from test_main a where exists
     (select * from test_main b where a.date>b.date and a.title=b.title);已经测试,lz放心使用。
      

  3.   

    --如果按照title  
    select a.*
      from test_main a
     where not exists (select *
              from test_main b
             where a.title = b.title
               and b.date > a.date)
     order by a.title;--如果按照id  
    select a.*
      from test_main a
     where not exists (select *
              from test_main b
             where a.id = b.id
               and b.date > a.date)
     order by a.id;