For example, I have
tabela_A
:
cod nome
1 stack
2 overflow
3 stackoverflow
and tabela_B
:
cod_tabela_A ano mes valor
1 2016 1 100
1 2016 2 115
2 2016 1 90
When done a LEFT JOIN, it returns me the following, in the correct way:
SELECT * FROM tabela_A a
LEFT JOIN tabela_B b ON a.cod = b.cod_tabela_A
cod nome cod_tabela_A ano mes valor
1 stack 1 2016 1 100
1 stack 1 2016 2 100
2 overflow 2 2016 1 90
3 stackoverflow NULL NULL NULL NULL
If I add the WHERE clause:
SELECT * FROM tabela_A a
LEFT JOIN tabela_B b ON a.cod = b.cod_tabela_A
WHERE ano = 2016 AND mes = 2
It returns me a single record, correctly:
cod nome cod_tabela_A ano mes valor
1 stack 1 2016 2 100
But what I need is that when I do not obey the values indicated in WHERE, I get NULL:
cod nome cod_tabela_A ano mes valor
1 stack NULL NULL NULL NULL
1 stack 1 2016 2 NULL
2 overflow NULL NULL NULL NULL
3 stackoverflow NULL NULL NULL NULL
Is there any way to get this result?