SQL Server joining tables with null

Asked

Viewed 53 times

2

I have the following tables:

Responsavel             |     Filho
Id      Nome            |     Id    Nome           ResponsavelId
1       Ana             |     1     Aninha         1
2       Maria           |     2     Ana Júlia      1
3       Pedro           |     3     Mariazinha     2

I’d like to make a SELECT with INNER JOIN where it presented the following result:

Id    Responsavel     Filho
1     Ana             Aninha
1     Ana             Ana Júlia
2     Maria           Mariazinha
3     Pedro           NULL

I need that amount null. Could someone help me? I should use Left Join?

1 answer

2


You need to use the LEFT JOIN, read more about in that reply.

SELECT 
    Responsavel.Id
    Responsavel.Nome,
    Filho.Nome
FROM Responsavel
LEFT JOIN Filho
    ON Responsavel.Id = Filho.ResponsavelId

Browser other questions tagged

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