Show NULL SQL values

Asked

Viewed 201 times

2

Good evening, I’m new to SQL and I have a question.

I have the following database:

inserir a descrição da imagem aqui

My goal is to present the name of the employees, their function and the name of the department where they work having to be the result ordered by the name of the department and within the department by the name of the employee. However I am asked to present the name of the department where no one works, the result being equal to the following image:

inserir a descrição da imagem aqui

Without the NULL part I know the code would be:

select emp.nome, emp.funcao, dep.nome 
from emp, dep 
where emp.ndep = dep.ndep
order by dep.nome, emp.nome;

However I can not find a way to include NULL in the table, I tried using IS NULL but it gives me error, probably because I am using it badly. Can someone give me a hand?

Thank you

1 answer

0

Hello,

You can use left Join:

SELECT * FROM [emp] AS [e] 
LEFT JOIN [dep] AS [d] ON e.ndep = d.ndep
order by [d].nome, [e].nome;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.