4
The situation found was that:
I am making a junction between representatives and sellers, and in another situation this junction is made with another sales. There are sales without sellers but are related to the representative, and I want to capture and verify the failure of this relationship in these sales.
Problem:
I’m making a LEFT JOIN
And to some extent he meets me according to the very limitation of the clause. Only I need that when I make a relationship between the representative and the sellers, even if he finds some of them, also return me a NULL
.
Current example:
SELECT r.cod as cod_representante, v.cod_vendedor
FROM representantes r
LEFT JOIN vendedores v
ON v.cod_representante = r.cod
It returns to me something like :
cod_representante | cod_vendedor
1 | 1
1 | 2
2 | NULL
3 | NULL
4 | 3
The desired result would be something like:
cod_representante | cod_vendedor
1 | 1
1 | 2
1 | NULL
2 | NULL
3 | NULL
4 | 3
4 | NULL
you want, for each cod_representative to have a corresponding NULL in cod_seller, even if cod_seller has a corresponding value?
– Marco Souza
Exactly, @Gokussjgod. Even if it has values in the merge, I want to increment one more value, being NULL.
– Marcelo de Andrade
Quite strange your need, but I believe you have to make one more union of your tables, perhaps being in a subselect. Could post your tables ?
– Marco Souza
Yes, it is strange but it was the temporary solution I saw and that immediately meets this problem I described.
– Marcelo de Andrade
It worked the way I posted it?
– Marco Souza
Yes, I did, making some adaptations but it served me well.
– Marcelo de Andrade