t1
date                                 id
2008-02-26 09:46:37.737 139 46000
2008-02-26 20:22:28.357 139 46000t2id 
46000结果2008-02-26 09:46:37.737 139 46000

解决方案 »

  1.   


    select min(a.date),a.id from t1 a left join t2 b on a.id=b.id group by a.id
      

  2.   

    忘了说表1 还有其他列,ms,cell,op_date
      

  3.   

    group by 会提示因为该列没有包含在聚合函数或 GROUP BY 子句中。
      

  4.   

    select a.* from t1 a left join t2 b on a.id=b.id where not exists (select 1 from t1 where date>a.date)
      

  5.   

    实际开发中也碰到此需求,直接的简单的sql语句不行
      

  6.   

    上面那个是去最大的时间
    下面这个是取最小的时间 
    select a.* from t1 a left join t2 b on a.id=b.id where not exists (select 1 from t1 where date<a.date)
      

  7.   

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

  8.   

    谢谢大家,尤其小虫,枪手!不过我按狙击手(11),做了。distinct 后还是有很少条重复的记录
    不过没大碍。道理还是不很清楚