2
Good evening, I’m new to SQL and I have a question.
I have the following database:
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:
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
Why NULL values are not selected?
– Marconi
What do you mean? I don’t understand the question
– João Sacramento
John see the answers.
– Marconi
Understand the difference between INNER JOIN and OUTER JOIN can help you bring nulls in a reply
– Bacco
Read what @Bacco commented and then try Join using a
left join
for example, which allows you to bring values from one table even if there is no linking value in the other table– Ricardo Pontual