select 
    a.id,
    a.name,
    a.taskname,
    a.detail,
    b.status,
    b.time 
from 
    表a a,
    表b b 
where 
    a.id=b.id and not exists(select 1 from 表b where id=b.id and sid>b.sid)

解决方案 »

  1.   

    select a.id, a.name ,taskname ,detail ,status ,max(b.time)  from 表a  a inner join 表b   b  on a.id=b.id group by
    a.id,a.name,taskname,detail,status 
      

  2.   

    select a.id, a.name ,b.taskname ,b.detail ,b.status ,max(b.time)  from 表a , 表b  where a.id=b.id group by
    a.id,a.name,b.taskname,b.detail,b.status
      

  3.   

    谢谢,楼上的不行,我是想同时查出taskid为1和为3以及符合某一条件的一系列taskid的类似记录。
      

  4.   

    还是不行,如果group by 中有status字段的话会出现如下情况
    id name taskname detail status time
    1  n1    t1        d1    s3     t4
    1  n1    t1        d1    s2     t1
    3  n3    t3        d3    s2     t3
      

  5.   

    Select A.id,name,taskname,detail,T.status,T.time From A inner join (
    Select B.id,B.status,B.time From B inner join 
    (Select id,max(time) time From B Group By id) C
    on B.time=C.time) T on A.id=T.id
      

  6.   

    select aa.*,a.time from aa,(select b.* from bb b  where time in(select max(time) from bb c group by id))a where aa.id=a.id