如何从三个表中获取特定记录

发布于 2024-08-18 17:18:09 字数 550 浏览 3 评论 0原文

表名 :: 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

  1. sub_id(学科ID)
  2. sub_name(学科名称0
  3. f_id(Faculty ID)

表名::faculty_master

Fields

  1. f_id(Faculty Id)
  2. f_name(Faculty Name)
  3. l_name(Faculty Name)
  4. 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

  1. sub_id (subject Id)
  2. sub_name (Subject Name0
  3. f_id ( Faculty ID)

Table Name :: faculty_master

Fields

  1. f_id (Faculty Id)
  2. f_name (Faculty Name)
  3. l_name (Faculty Name)
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一生独一 2024-08-25 17:18:09

使用对象

Select T1.f_name, T2.sub_name, T3.remark from faculty_master as T1, 
subject_master as T2, Feedback_master as T3 where T1.f_id = 'your faculty_id'
and T1.f_id = T3.f_id and T2.sub_id = T3.sub_id

Using Objects

Select T1.f_name, T2.sub_name, T3.remark from faculty_master as T1, 
subject_master as T2, Feedback_master as T3 where T1.f_id = 'your faculty_id'
and T1.f_id = T3.f_id and T2.sub_id = T3.sub_id
等数载,海棠开 2024-08-25 17:18:09

嘿,我猜是MySQL?

SELECT f_name, sub_name, remark 
FROM faculty_master
LEFT JOIN subject_master USING(f_id)
LEFT JOIN Feedback_master USING(f_id)
WHERE f_id = the_id_you_want

heu, MySQL I presume?

SELECT f_name, sub_name, remark 
FROM faculty_master
LEFT JOIN subject_master USING(f_id)
LEFT JOIN Feedback_master USING(f_id)
WHERE f_id = the_id_you_want
清风夜微凉 2024-08-25 17:18:09

选择 fm.f_name、sm.sub_name、favorite_master fm left 的备注
在 fm.f_id=sm.f_id 上加入 sub_master sm
左加入feedback_master fbm on
sm.sub_id = fbm.sub_id
其中 fm.f_id=123

select fm.f_name, sm.sub_name, remark from faculty_master fm left
join sub_master sm on fm.f_id=sm.f_id
left join feedback_master fbm on
sm.sub_id = fbm.sub_id
where fm.f_id= 123

酒废 2024-08-25 17:18:09

您可以分阶段构建查询。首先,您需要一份反馈意见列表,因此从这个简单的 开始选择查询

SELECT * FROM Feedback_master

这列出了来自各地的所有反馈,但您希望将其限制为仅针对特定教师的反馈,因此让我们添加一个Where 子句

SELECT * FROM Feedback_master
  WHERE Feedback_master.f_id = @f_id

现在我们得到了正确的记录列表,但字段列表是错误的。您需要教师姓名和学科名称,而 Feedback_master 表中没有这些信息; subject_master 和 coach_master 表是链接的,假设每个评论都有一个主题 ID 和一个教员 ID,我们可以使用一个简单的 内连接来链接表:

SELECT * FROM Feedback_master
  INNER JOIN subject_master ON Feedback_master.sub_id = subject_master.sub_id
  INNER JOIN faculty_master ON Feedback_master.f_id = faculty_master.f_id
  WHERE Feedback_master.f_id = @f_id

现在它从所有三个表中提取所有字段;这包括我们需要的所有字段,因此我们现在可以简单地在 Select 子句中命名它们:

SELECT
  faculty_master.f_name, subject_master.sub_name, Feeback_master.remark
FROM Feedback_master
  INNER JOIN subject_master ON Feedback_master.sub_id = subject_master.sub_id
  INNER JOIN faculty_master ON Feedback_master.f_id = faculty_master.f_id
WHERE Feedback_master.f_id = @f_id

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:

SELECT * FROM Feedback_master

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:

SELECT * FROM Feedback_master
  WHERE Feedback_master.f_id = @f_id

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:

SELECT * FROM Feedback_master
  INNER JOIN subject_master ON Feedback_master.sub_id = subject_master.sub_id
  INNER JOIN faculty_master ON Feedback_master.f_id = faculty_master.f_id
  WHERE Feedback_master.f_id = @f_id

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:

SELECT
  faculty_master.f_name, subject_master.sub_name, Feeback_master.remark
FROM Feedback_master
  INNER JOIN subject_master ON Feedback_master.sub_id = subject_master.sub_id
  INNER JOIN faculty_master ON Feedback_master.f_id = faculty_master.f_id
WHERE Feedback_master.f_id = @f_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文