select * from table where id='001' order by timeif (rs.next()) {
  第一条记录就是最新的
}

解决方案 »

  1.   

    select * from table where id='001' order by time desc
    第一条数据就是最新记录
      

  2.   

    select * from table where id='001' order by time desc limit 1
      

  3.   

    select * from table where id='001' order by time desc
    它会把刚输入的数据,也就是最新记录,自动做为第一条显示出来。
      

  4.   

    select top 1 * from table where id='001' order by time desc
      

  5.   

    谢谢大家不过发现问题提错了,
    表table1
       id     time           content
       001    2003-07-10      第一条
       002    2003-07-11      一条
       001    2003-08-01      第二条
       002    2003-08-09      一条
       001    2003-08-11      最后一条
    表table2
       id     time           detail      bak
       003    2003-07-10      第一条      haha
       004    2003-07-11      一条        haha
       003    2003-08-01      第二条      haha
       004    2003-08-09      一条        haha
       003    2003-08-11      最后一条    haha我现在想取出不同id的最后一条记录
    得出的结果如下
      001    2003-08-11      最后一条
      002    2003-08-09      一条
      003    2003-08-11      最后一条
      004    2003-08-09      一条请高手再指教一下,一定给分!以上兄弟我也会给分的,多些!请注意表的有些字段是不同的
      

  6.   

    谢sql语句
    select top 1 id,time,content 
    from table1 where id in 
    (select distinct id from table1)
    order by time desc
    union
    select top 1 id,time,content 
    from table1 where id in 
    (select distinct id from table1)
    order by time desc
    union
    select top 1 id,time,detail as content 
    from table2 where id in 
    (select distinct id from table1)
    order by time desc
    union
    select top 1 id,time,detail as content 
    from table2 where id in 
    (select distinct id from table1)
    order by time desc
      

  7.   

    select top 1 id,time,content 
    from table1 where id ='001'
    order by time desc
    union
    select top 1 id,time,content 
    from table1 where id ='002'
    order by time desc
    union
    select top 1 id,time,detail as content 
    from table2 where id ='003'
    order by time desc
    union
    select top 1 id,time,detail as content 
    from table2 where id ='004'
    order by time desc
    还是写存储过程吧
    似乎sql扛不住
      

  8.   

    问题虽然没解决,可ccmoon(IzuaL) 给我不少提示
    想多给大家点分,可系统不允许,只好对不起大家了!
      

  9.   


    select * from table A ,(select id,max(time) from table group by id) B where A.id=B.id and A.time=B.time
      

  10.   

    参考楼上的
    其实主要的创意还是楼上的
    这个问题也得到了完美的解决
    select id,time,content 
    from table1 A ,(select id,max(time) from table1 group by id) B 
    where A.id=B.id and A.time=B.time
    union
    select id,time,detail as content
    from table2 C ,(select id,max(time) from table2 group by id) D 
    where C.id=D.id and C.time=D.time