我正在使用MySQL。以下是我的SQL语句。 timetabledistribution
是我的交易表。这工作正常。但是这是返回NULL
记录时teacherId = NULL
timetabledistribution
表中有记录。 我相信这是因为SQL语句中有一个INNER JOIN teacher_profiles c ON a.teacherId = c.teacherId
。 如果teacherId = NULL,那么有没有可能避免或忽略此JOIN?或任何其他更好的办法...INNER JOIN导致NULL RECORD SET
SELECT
CONCAT(a.periodWeekDayId, '.', a.periodId) as Id,
a.periodId,
a.periodWeekDayId,
a.subjectId,
b.subjectShortName,
a.teacherId,
CONCAT(c.teacherFirstName , ' ', COALESCE(c.teacherMiddleName, ''), ' ', c.teacherLastName) as teacherName ,
e.classStd,
f.sectionName,
g.templateName,
h.periodLabel,
h.periodStartTime,
h.periodEndTime,
i.periodWeekDayName,
a.timeTableClassSectionId
FROM timetabledistribution a
INNER JOIN subject_master b ON a.subjectId = b.subjectId
INNER JOIN teacher_profiles c ON a.teacherId = c.teacherId
INNER JOIN TimeTableClassSection d ON a.TimeTableClassSectionId = d.TimeTableClassSectionId
INNER JOIN class_master e ON d.classId = e.classId
INNER JOIN section_master f ON d.sectionId = f.sectionId
INNER JOIN TimeTableTemplate g ON d.timeTableTemplateId = g.timeTableTemplateId
INNER JOIN templatePeriodStructure h ON a.periodId = h.periodId
INNER JOIN templateWeekDaysStructure i ON a.periodWeekDayId = i.periodWeekDayId
WHERE A.TimeTableClassSectionId='46'
我想现场的其余部分应该是除了老师详细的teacherId返回NULL的特定记录。 但是查询忽略了整个记录。
Id periodId periodWeekDayId …..
1 12 1
但得到
Id periodId periodWeekDayId …..
NULL NULL NULL
我有点困惑.... 你试过使得JOIN教师配置文件的LEFT OUTER 因此改变........ LEFT OUTER JOIN teacher_profiles c ON a.teacherId = c.teacherId – AntDC
有意义..我想我错过了..谢谢你的建议 – fresher
@AntDC把它放到你的答案中。 – Barmar