我有一个学生表,其中包含以下列:StudID、Name和StudNIC。
我有另一个包含列的表studentBack:StudBackID和StudMID
我有另一个具有列的表studentLab:StudBackID。
当我对表studentLab上的特定学生执行WHERE条件时,没有返回任何记录。
我想检索那些在studentLab中没有记录的学生的名字。我如何在SQL中实现这一点?
发布于 2016-09-07 13:59:15
使用LEFT JOIN,您可以在studentLAB表列下获得studentLab表中缺少的记录的NULL值,您可以使用IS NULL条件在WHERE集中进行过滤
SELECT student.Name
FROM student
INNER JOIN studentBack ON student.StudID = studentBack.StudMID
LEFT JOIN studentLab ON studentLab.StudBackID = studentBack.StudBackID
WHERE studentLab.StudBackID IS NULL发布于 2016-09-07 13:59:38
SELECT s.Name
FROM student s
LEFT JOIN studentBack sb
ON s.StudID = sb.StudMID
LEFT JOIN studentLab sl
ON sb.StudBackID = sl.StudBackID
WHERE sl.StudBackID IS NULL对于那些与studentLab表中的任何记录都不匹配的学生,WHERE子句中的IS NULL条件将为真。
https://stackoverflow.com/questions/39362113
复制相似问题