1

我有三个表,我想在第一个表中查看来自其他表的值。让我更好地解释一下:

餐桌课

+------------------+----------------+----------------+------------+-----------+
| LessonCode       | SubjectCode    | ClassCode      | hour       | day       |
+------------------+----------------+----------------+------------+-----------+
| 1                | 10             | 1              | 15         | m         |
| 2                | 11             | 2              | 20         | t         |
| 3                | 12             | 3              | 30         | w         |
+------------------+----------------+----------------+------------+-----------+

表类

+------------------+----------------+
| ClassCode        | ClassName      |
+------------------+----------------+
| 1                | Class1         |
| 2                | class2         |
| 3                | class3         |
+------------------+----------------+

表主题

+------------------+----------------+
| subjectCode      | SubjectName    |
+------------------+----------------+
| 10               | Maths          |
| 11               | English        |
| 12               | Greek          |
+------------------+----------------+

我想在lesson表格中插入列SubjectNameClassName代替SubjectCodeand ClassCode,并具有以下表格:

+------------------+----------------+----------------+------------+-----------+
| LessonCode       | SubjectName    | ClassName      | hour       | day       |
+------------------+----------------+----------------+------------+-----------+
| 1                | Maths          | Class1         | 15         | m         |
| 2                | English        | Class2         | 20         | t         |
| 3                | Greek          | Class3         | 30         | w         |
+------------------+----------------+----------------+------------+-----------+

我能怎么做?

4

1 回答 1

3

这看起来像是JOINs 的工作! INNER JOIN救援!

SELECT LessonCode, SubjectName, ClassName, hour, day
FROM lesson
JOIN class on lesson.ClassCode = class.ClassCode
JOIN subject on lesson.SubjectCode = subject.SubjectCode
于 2013-09-17T18:15:51.133 回答