I made this code Join, I got it to return the expected values, but the values appear repeated. (Obs: I am beginner in Database)

Asked

Viewed 18 times

0

inserir a descrição da imagem aqui

select CLI_NOME, TEC_TELEFONE from tb_clientes 
 join tb_tel_clientes on   CLI_BAI_CODIGO = CLI_BAI_CODIGO 
 where CLI_BAI_CODIGO in(2,3,4) order by CLI_NOME;
  • 1

    I could not identify repeated values in the image you presented.

  • the cli_name in the image, John Mary appears several times, and the other clients who correspond both to neighborhoods 3 and 4, happens the same

  • But they appear along with different phones, which is what is expected for a select with a merge operation.

  • vdd, after doing 3 different ways I stopped to observe this, thank you :)

1 answer

0

Not knowing the structure of the table, it seems that the field CLI_BAI_CODIGO only belongs to one column (otherwise the BD engine would complain that it could not know to which table the field would refer).

For this reason, the junction condition as it is is equivalent to " 1 = 1 " or always true (the behavior would be the same if it were not even present). When this happens, the result obtained is the combination of all the rows of the first table with all the rows of the second table (operation also called produto interno). On this result space the filter is applied on the lines that refer to the `CLI_BAI_CODIGO IN (2,3,4)``.

Together all this, the first column appears duplicated (because it belongs to the same table as the field CLI_BAI_CODIGO.

I hope it helps to understand the behavior, but as I said at the beginning, without the details of the scheme it is not possible to give details without being speculation.

Browser other questions tagged

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