小弟我想做一个论坛,可是遇到了,下面问题:
我有三个表:(sort)版面分类表、(topic)主题表、(response)回复主题表。
具体如下:sort表:
----------------------------------
s_id s_name    master
----------------------------------topic 表:
--------------------------------------------------
t_id s_id t_name U_name t_time t_content
--------------------------------------------------response 表:
--------------------------------------------------
r_id t_id U_name r_content r_time
--------------------------------------------------小弟我现在想查询:topic 表中的所有信息根据s_id 并查询每个主题所对应的回贴数。
就是这个问题我搞了好几天都没结果。
请问如何实现????

解决方案 »

  1.   

    select count(*) from response where t_id=XXXXX
      

  2.   


    这样只能查询到response表中对应的topic 的回复次数,不能查询到topic 表中的内容啊??
      

  3.   

    select a.*, b.count(*) from topic a, response  b where a.t_id = b.t_id and a.s_id = ? group by t_id
      

  4.   

    还是不行,只查询得出部分记录,不能把topic表中对应s_id的所有记录查询出来?????
      

  5.   

    应该可以呀!!还是你的运行SQL的客户端控制了显示条数
      

  6.   

    没有我的是sql2000,在查询分析器中试了,只查询得出部分记录,不能把topic表中对应s_id的所有记录查询出来?????
      

  7.   

    select 主题=a.t_content,次数=(select count(*) from response where t_id=a.t_id) from topic as a