【发布时间】:2015-02-14 04:09:17
【问题描述】:
我有一个包含这两个表的数据库 - questions 和 answers。
表定义
questions - id, question, asked_by
answers - id, question_id(foreign key), answers, sent_by
我想计算并回显每个问题的答案总数。
样本数据
question
id question asked_by
1 how r u emma
2 r u ok sam
answer
id question_id answer sent_by
1 2 good john
2 1 fine sam
3 2 WTG biggie
在显示所有问题的页面上,我想按每个问题和答案的数量来写。 question2= 2 和 question1=1 的答案数。
【问题讨论】:
-
好吧,对于这样的情况,我更喜欢 join 从 2 个表中选择行 Read this tutorial on join