求sql语句,left join

骄傲青蛙 2010-04-04 08:38:03
A(tid,fid,subject) //A table

B(aid,tid,name) //B table

select A.*, count(*) from A left join B On A.tid = B.tid;

A表每条记录都唯一的,B表的tid字段有很多相同,

现在要查询A表之后,在最后一列加入B表以A.tid这个条件查询的记录的总条数,

这样写对不,好像没效果。
...全文
39 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
骄傲青蛙 2010-04-04
  • 打赏
  • 举报
回复
I finish myself when i posted the article, but thanks for ACmAIN_CHM who are good man.
ACMAIN_CHM 2010-04-04
  • 打赏
  • 举报
回复
select a.tid,a.fid,a.subject,count(b.tid)
from a left join b on a.tid=b.tid
group by a.tid,a.fid,a.subject

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧