Data repeats instead of null

Asked

Viewed 32 times

0

inserir a descrição da imagem aqui

People do not know if this is normal in sql but I will post here to clear my doubt. I have a query with three tables using INNER JOIN, apparently the result is favorable, but a small detail bothers me. see the example. What happens is the following in the codigo_store column where is 1 there are no values in the cod_store column and cod_list column, should return me null and not 3 and 1. I do not know if this is an error the normal behavior. Because where is 1 in the code_store column I know that the rest does not exist. I’m sorry more I am very new in mysql.

SELECT b.cod_produto, b.nome_produto, a.cod_loja, a.cod_lista, c.codigo_loja, c.preco_produto, b.preco_produto
FROM lista_de_compras AS a
lEFT JOIN itens_lista_compras AS b ON a.cod_lista = b.cod_lista
LEFT JOIN loja_produto AS c ON b.cod_produto = c.codigo_produto
WHERE a.cod_lista =1
  • I would have to see how you are doing the consultation. It would be good to post the question.

  • I think I know what’s going on, I have a products table that relates to cod_product n:n with table 1 and table2. The Tabela1 with the cod_product table generates cod_prodTabela1 and table2 with cod_product generates cod_prodTabela2, then I do an INNER JOIN WITH cod_prodTabela1, cod_prodTabela2 must be because the two relate to cod_product with the same id. Would that be?

No answers

Browser other questions tagged

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