3

I'm trying to create a query that will display the name of the staff who are not mentoring any other staff. It should also be ordered by the surname.

So far, I've got this:

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;

When I run the query it doesn't return any results.

Any help would be nice.

4

2 回答 2

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;
于 2013-11-03T12:28:42.367 回答
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

于 2013-11-03T12:29:53.213 回答