在SQL中创建查询

时间:2013-11-03 12:23:35

标签: sql

我正在尝试创建一个查询,显示不指导任何其他员工的员工姓名。它也应该由姓氏订购。

到目前为止,我已经有了这个:

SELECT a.name, m.mentor
FROM accountant AS a 
LEFT OUTER JOIN accountant AS m ON a.mentor = m.staff_id
WHERE m.mentor = NULL
ORDER BY m.surname;

当我运行查询时,它不会返回任何结果。

任何帮助都会很好。

2 个答案:

答案 0 :(得分:4)

尝试使用IS Null Not = Null

SELECT a.name, m.mentor
FROM accountant AS a LEFT OUTER JOIN accountant AS m
ON a.mentor = m.staff_id
WHERE m.mentor is NULL ///  here
ORDER BY m.surname;

答案 1 :(得分:1)

SELECT a.name, m.mentor
FROM accountant AS a LEFT OUTER JOIN accountant AS m
ON a.mentor = m.staff_id
WHERE m.mentor IS NULL
ORDER BY m.surname;

您需要使用IS NULL,无法检查值equals(=)是否为NULL