SQL查询语句问题

[复制链接]
查看11 | 回复3 | 2010-5-10 13:55:20 | 显示全部楼层 |阅读模式
有两个表,article和article_msg两个表,我想在文章列表页面同时输出文章表中的信息以及对应的该文章的留言总数,只用一句SQL。不知道哪个高手能指导指导

回复

使用道具 举报

千问 | 2010-5-10 13:55:20 | 显示全部楼层
select a.id, a.content, b.c from (select id, content from article) a, (select id, count(1) as c from article_msg group by id) b where a.id = b.id大致如此
回复

使用道具 举报

千问 | 2010-5-10 13:55:20 | 显示全部楼层
select *,(select count(*) from article_msg where 文章ID=article.id)from article
回复

使用道具 举报

千问 | 2010-5-10 13:55:20 | 显示全部楼层
select a.name,count(*) from article a,article_msg bwhere a.id=b.id group by a.name
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行