两张表 1.ClassSubjectTable和2.SubjectTable
ClassSubjectTable
------------------------------------
class_subject_id |subject1 |subject2
------------------------------------
1 (General Id) | 1 | 2 -----> are subject_id's
SubjectTable
-------------------------
subject_id | subject_name
-------------------------
1 | Maths
2 | Science
我想要
------------------------------------
class_subject_id |subject1 |subject2
------------------------------------
1 |Maths | Science
他们之间没有任何关系。可能吗?怎么样?
答案 0 :(得分:1)
简单JOIN
:
SELECT c.class_subject_id, s1.subject_name AS subject1, s2.subject_name AS subject2
FROM ClassSubjectTable c
LEFT JOIN SubjectTable s1
ON c.subject1 = s1.subject_id
LEFT JOIN SubjectTable s2
ON c.subject2 = s2.subject_id;
的 SqlFiddleDemo
强>