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.

2
  • 2
    Show us table structure. Commented Nov 3, 2013 at 12:25
  • 1
    Any sample data with tables structure would be nice also Commented Nov 3, 2013 at 12:25

2 Answers 2

4

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;
Sign up to request clarification or add additional context in comments.

Comments

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;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.