I need to return the null values of this inner join

2

I have this select of MySQL:

SELECT credor.nome, banco.descricao FROM credor
INNER JOIN banco ON (credor.banco = banco.codigo)

It returns me all the lenders and their respective bank, but if the bank of the guy is NULL it just does not return the registry.

How can I do to return the record but in the description get NULL?

    
asked by anonymous 10.11.2015 / 20:00

1 answer

6

What INNER JOIN does is just eliminate NULL s. It only establishes a relationship when there is no NULL on either end.

What you're looking for is done with LEFT JOIN :

SELECT credor.nome, banco.descricao FROM credor
LEFT JOIN banco ON (credor.banco = banco.codigo)

Here on the site you have an excellent explanation of the types of JOIN : What is the difference between INNER JOIN and OUTER JOIN? / a>

    
10.11.2015 / 20:03