Show NULL SQL values [duplicate]

2

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

I have the following database:

Mygoalistopresentthenamesoftheemployees,theirroleandthenameofthedepartmentwheretheywork,havingtobetheresultorderedbythenameofthedepartmentandwithinthedepartmentbythenameoftheemployee.HoweverIamaskedtopresentthenameofthedepartmentwherenooneworks,havingtheresultofbeingequaltothefollowingimage:

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 figure out how to include NULL in the table, I've tried using IS NULL but it gives me an error, probably because I'm using it badly. Can someone help me?

Thank you

    
asked by anonymous 11.10.2018 / 22:43

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;
    
11.10.2018 / 23:04