SQL Server连接查询以获取所有主题

时间:2015-08-15 06:41:05

标签: join sql-server-2005

我有三张桌子:

TBL_SUBJECTTBL_SEMESTERTBL_SUBJECT_SEMESTER_MAPPING

我正在subjectId跟我说'1',我想得到我的科目所属学期的所有科目。即具有Id' 1'。

的主题

如何使用SQL Server中的连接进行查询。

2 个答案:

答案 0 :(得分:0)

你的问题不尽如人意。请发布模式以获得更好的答案。

答案将是这样的:

SELECT 
    SEMESTER_NAME 
FROM 
    TBL_SEMESTER 
INNER JOIN 
    TBL_SUBJECT_SEMESTER_MAPPING ON TBL_SUBJECT_SEMESTER_MAPPING.SUBJECTID = TBL_SEMESTER.SUBJECTID
INNER JOIN 
    TBL_SUBJECT TBL ON TBL_SUBJECT.SUBJECTID = TBL_SUBJECT_SEMESTER_MAPPING.SUBJECTID
WHERE 
    SUBJECTNAME LIKE YOURSUBJECT

答案 1 :(得分:0)

我这样做了

SELECT *来自tbl_subject S
INNER JOIN tbl_subject_semester_mapping SSP ON SSP.subId = S.subId
INNER JOIN tbl_semester SEM SEM.semId = SSP.semId
WHERE SEM.semId =(从tbl_subject_semester_mapping TSSM中选择semId,其中TSSM.subId = 1)