首页 > 解决方案 > 如何更新学生成绩的联结表中的行

问题描述

我又来了。非常感谢您的帮助。

这是我关于如何在连接表中选择和显示学生成绩的老问题。

选择并显示属于特定 ID 的所有行

我成功地做到了,但现在我无法更新连接表中的成绩。

这是我的示例表。

    "student"
-----------------------
|studentID | FullName |
-----------------------
|1234      | John    |
|1235      | Michael |
|1236      | Bryce   |

        "subject_bsit"
-----------------------------------
|subject_id| subject_name  |grade |
-----------------------------------
|    1     | Programming   |  3   |
|    2     | Networking    |  2.5 |
|    3     | Algorithm     |  1.75|
|    4     | Physical Educ |  2   |

This is the Junction table to connect the 
two now.

       "student_subject"
----------------------------
| student_id | subject_id |
----------------------------
|   1235     |      1     |
|   1235     |      2     |
|   1235     |      3     |
|   1234     |      1     |

这是我所做的查询。这是一个示例,我试图更新 具有subject_id = 1的studentID 1235的成绩

更新 3:

sql = "UPDATE student_subject " & _
    " INNER JOIN subject_bsit " & _
    " ON subject_bsit.subject_id = student_subject.sub_id " & _
    " SET grade = 1 " & _
    " where student_subject.student_id='" & Txtbox.Text & "' AND student_subject.sub_id = 1"

& Txtbox.Text & 是用户输入学生身份的地方,不要介意。非常感谢我使用 Visual studion vb.net。

这是我得到的确切错误。

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“FROM student_subject INNER JOIN subject_bsit ON subject_bsit.subject_id = studen”附近使用正确的语法

标签: mysqlsqldatabasevb.netphpmyadmin

解决方案


您的查询不稳定,应该如下所示

UPDATE student_subject 
INNER JOIN subject_bsit 
ON subject_bsit.subject_id = student_subject.sub_id 
SET grade=? 
where student_subject.student_id='" & Txtbox.Text & "' AND student_subject.sub_id = 1

推荐阅读