如何从三个表中获取特定记录
表名 :: Feedback_master
字段 1. feed_id 2. roll_id 3. batch_id 4. sem_id(学期 ID) 5.f_id(教师 ID) 6. sub_id(科目 ID) 7. 备注。 8. b_id
表名::subject_master
Fields
- sub_id(学科ID)
- sub_name(学科名称0
- f_id(Faculty ID)
表名::faculty_master
Fields
- f_id(Faculty Id)
- f_name(Faculty Name)
- l_name(Faculty Name)
- b_id
这是三个表现在我想从这三个表中获取详细信息,
我希望输出为
f_Name(教师名称)、Sub_name(主题名称)和备注(备注)。
当我给出(教师 ID)f_id 时, 克服这个问题。
Table Name :: Feedback_master
Fields 1. feed_id 2. roll_id 3. batch_id 4. sem_id (semester ID) 5.f_id (faculty Id) 6. sub_id (subject Id) 7. remark. 8. b_id
Table Name :: subject_master
Fields
- sub_id (subject Id)
- sub_name (Subject Name0
- f_id ( Faculty ID)
Table Name :: faculty_master
Fields
- f_id (Faculty Id)
- f_name (Faculty Name)
- l_name (Faculty Name)
- b_id
This are the three tables. Now I want to fetch the detail from this three table.
I want the output as
f_Name (faculty name), Sub_name (Subject Name ) , and remark (Remark ) when i give the (faculty id) f_id
could some one help me to over come this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用对象
Using Objects
嘿,我猜是MySQL?
heu, MySQL I presume?
您可以分阶段构建查询。首先,您需要一份反馈意见列表,因此从这个简单的 开始选择查询:
这列出了来自各地的所有反馈,但您希望将其限制为仅针对特定教师的反馈,因此让我们添加一个Where 子句:
现在我们得到了正确的记录列表,但字段列表是错误的。您需要教师姓名和学科名称,而 Feedback_master 表中没有这些信息; subject_master 和 coach_master 表是链接的,假设每个评论都有一个主题 ID 和一个教员 ID,我们可以使用一个简单的 内连接来链接表:
现在它从所有三个表中提取所有字段;这包括我们需要的所有字段,因此我们现在可以简单地在 Select 子句中命名它们:
You can build up the query in stages. The first thing is that you're after a list of feedback remarks, so start with this simple select query:
That's listing all the feedback from all over, but you want to limit it to only feedback on a particular faculty, so let's add a Where clause:
Now we've got the right list of records, but the list of fields is wrong. You want the faculty name and subject name, which aren't there in the Feedback_master table; the subject_master and faculty_master tables are linked and assuming that every remark has a subject ID and a faculty ID, we can use a simple inner join to link the tables:
Now it's pulling out all the fields from all three table; this includes all the fields we need, so we can now simply name them in the Select clause: