Repeated values when making an INNER JOIN

0

This code below is bringing repeated values to the screen.

Could anyone help me?

$id_credenciado = $_SESSION['id_credenciado'];    

//$sql = mysqli_query($conn, "SELECT DISTINCT * FROM tb_protocolo INNER JOIN tb_certidao ON tb_protocolo.id_credenciado = tb_certidao.id_credenciado WHERE tb_protocolo.id_credenciado = $id_credenciado AND tb_certidao.id_credenciado = $id_credenciado");

$sql = mysqli_query($conn, "SELECT DISTINCT * FROM tb_protocolo INNER JOIN tb_certidao WHERE tb_protocolo.id_credenciado = $id_credenciado AND tb_certidao.id_credenciado = $id_credenciado");
    
asked by anonymous 10.08.2018 / 21:19

2 answers

1

In fact, it is not bringing repeated values.

What happens is that the distinct compares all the columns.

Just one column in the record is different than it will already separate into two records.

To solve this you need to specify only the search columns you need, instead of all of them using the asterisk (*).

    
10.08.2018 / 22:20
0

Test to do so:

$sql = mysqli_query($conn, 
"SELECT DISTINCT p.* FROM tb_protocolo p INNER JOIN tb_certidao c ON c.id_credenciado = p.id_credenciado WHERE c.id_credenciado = $id_credenciado");

We are joining the certificate table in the query by linking to the main code of the first table.

    
10.08.2018 / 22:09