二个表
Topic  父表
Post   子表
二表通过TopicID关联
一对多的关系
现在需按以下要求查询:
查出Topic表中在Post表中最后回复的那条记录

解决方案 »

  1.   

    Topic表
    TopicID  |   title  |  createtimePost表
    PostID | Author | postTime | TopicID
      

  2.   

    select a.*,b.* from Topic a 
    INNER JOIN 
    (select * from Post t 
    where not exists(select 1 from Post where TopicID = t.TopicID and PostTime > t.PostTime)) b
    on a.TopicID = b.TopicID
      

  3.   

    select a.* 
    from topic a , (select top 1 topicID from post order by posttime desc ) b
    where a.topicID =b.topicID这样好像是比较慢的...
      

  4.   

    select a.* ,b.* from a inner join b on a.id=b.id
    order by 时间 desc