我有三张桌子:
TBL_SUBJECT
,TBL_SEMESTER
和TBL_SUBJECT_SEMESTER_MAPPING
我正在subjectId
跟我说'1',我想得到我的科目所属学期的所有科目。即具有Id' 1'。
如何使用SQL Server中的连接进行查询。
答案 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)