0
I’m making a INNER JOIN that joins the columns:
cd_devolucao
tabledevolucao
cd_itens_venda
tableitens_venda
cd_produto
tableproduto
valor_total
tableitens_venda
I’m wanting to do the INNER JOIN
of these columns in the table itens_devolucao
gathering the others that have foreign keys within the table itens_devolucao
. Only that are returning all of them empty.
The mistake is that when a register is inserted in the table itens_devolucao
INNER JOIN works, only I wanted INNER JOIN to work even with the empty table because I need to use data request in JSON.
SELECT devolucao.cd_devolucao, itens_venda.cd_itens_venda,
produto.cd_produto, itens_venda.valor_total FROM itens_devolucao
INNER JOIN devolucao ON (devolucao.cd_devolucao = itens_devolucao.cd_devolucao)
INNER JOIN itens_venda ON (itens_venda.cd_itens_venda = itens_devolucao.cd_itens_venda)
INNER JOIN produto ON (produto.cd_produto = itens_devolucao.cd_produto);
And your table
itens_devolucao
is empty? Is the definition of foreign keys correct? Post the definition of the tables involved and not just the drawing.– anonimo
Related: What is the difference between INNER JOIN and OUTER JOIN?
– Icaro Martins
I do not understand what your idea is. If there is no record
itens_devolucao
you want to return the Cartesian product from the other tables?– anonimo
@anonym exactly that, even though there is no record of
itens_devolucao
i want to return the INNER JOIN from the other tables.– user198162
@Vorbbel: You’d better review the concept of INNER JOIN.
– anonimo
See if this is what you want:
FROM itens_devolucao
RIGHT OUTER JOIN devolucao ON (devolucao.cd_devolucao = itens_devolucao.cd_devolucao)
RIGHT OUTER JOIN itens_venda ON (itens_venda.cd_itens_venda = itens_devolucao.cd_itens_venda)
RIGHT OUTER JOIN produto ON (produto.cd_produto = itens_devolucao.cd_produto)
– anonimo
@anonimo only returned the record of
cd_produto
, because I deleted the record ofitens_devolucao
that there was only one.– user198162
I could not understand what you want but the Cartesian product of your tables you get with:
SELECT devolucao.cd_devolucao, itens_venda.cd_itens_venda, 
produto.cd_produto, itens_venda.valor_total 
FROM itens_devolucao, devolucao, itens_venda, produto;
– anonimo
@anonym the way you spoke now realize how unnecessary was the use of INNER JOIN in this code, I had not realized it.
– user198162
But still does not return the column records.
– user198162