user2949666
user2949666

Reputation: 33

Creating Queries in SQL

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.

Upvotes: 3

Views: 68

Answers (2)

Christian Phillips
Christian Phillips

Reputation: 18749

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;

You need to use IS NULL, you cant check if the value is equals(=) to NULL

Upvotes: 1

Mahmoude Elghandour
Mahmoude Elghandour

Reputation: 2931

Try To Use 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;

Upvotes: 4

Related Questions