免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1598 | 回复: 1
打印 上一主题 下一主题

帮忙看一下这个sql读取对不对 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-02 20:59 |只看该作者 |倒序浏览
现在有两个表A thread B posts
表A thread    threadid

表B posts     postid  message  threadid
表A 54是主题
表B  122 131 137 都是 都属于thread 54  其中122( 也就是一个主题最新发表的帖子postid) message 是主题thread 54主题的内容  131 137是主题thread 54主题的回帖


$sql_select = "select threads.threadid,posts.postid,message from threads left join posts on threads.threadid=posts.threadid where 。。order by。。。LIMIT。。。。";

$sql_result = $db->query($sql_select);
while($row = $db->get_row($sql_result)){
略去n....。

$row['message']
略去n....。       
       
通过这个语句同时读取表A threadid 和表B 里 等于threadid最小 上面的SQL语句对不对 PS:也不知道大大们看懂了没

[ 本帖最后由 cnhunk 于 2008-7-2 21:04 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-07-03 22:04 |只看该作者
select posts.* from
      (select min_postid.min_postid as a,min_postid.threadid from
              thread left join
                     (select min(postid) as min_postid,threadid from posts group by threadid) as min_postid
       on thread.threadid=min_postid.threadid) as temp
left join posts on temp.a=posts.postid;
可以试试.ps:要看懂你的意思还确实不容易.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP