I need to perform a SQL query in PHP, where I need to create a table from other 9 tables, joining all the columns with a LEFT JOIN, and with the 'Client' field as the key between the tables. However, in each table there is more than one record of the same key, that is, more than one row with the same 'Customer' number, and thus the query is returning me repeated values, changing only the values of the columns that are different data. I would like these repeated values of the columns to only appear once, and in the others I would return with NULL. I will put below an image showing how the values are being returned to me. Does anyone have any idea how to solve this? Thank you so much!
Follow the query code:
SELECT *
FROM completo_sem_saldo
LEFT JOIN posicao_contabil ON (completo_sem_saldo.Cliente = posicao_contabil.Cliente)
LEFT JOIN saldo_analitico ON (completo_sem_saldo.Cliente = saldo_analitico.Cliente)
LEFT JOIN titulos_em_ser ON (completo_sem_saldo.Cliente = titulos_em_ser.Cliente
HOWIWANTYOUTORETURN:
TABLEFULLCODE:
$query1=mysqli_query($con,"SELECT * FROM completo_sem_saldo as a LEFT JOIN posicao_contabil as b ON (a.Cliente = b.Cliente_Posicao) LEFT JOIN saldo_analitico as c ON (a.Cliente = c.Cliente_Saldo_Analitico) LEFT JOIN titulos_em_ser as d ON (a.Cliente = d.Cliente_Titulos_Em_Ser) ) as e");
$num = mysqli_num_rows($query1);
$resul1 = mysqli_fetch_assoc($query1);
$arquivo = 'exemplo.xls';
$tabela = '<table border="1">';
$tabela .= '<tr>';
$tabela .= '<td colspan="2">Formulario</tr>';
$tabela .= '</tr>';
$tabela .='<tr>';
$tabela .='<td><b>Nome</b></td>';
$tabela .='<td><b>Sld_dev_ctbl</b></td>';
$tabela .= '<td><b>Saldo</b></td>';
$tabela .='<td><b>Vlr_atual</b></td>';
$tabela .='</tr>';
while($resul1 = mysqli_fetch_assoc($query1)) {
$nome = $resul1['Nome'];
$sld_dev_ctbl = $resul1['Sld_dev_ctbl'];
$saldo = $resul1['Saldo'];
$vlr_atual = $resul1['Vlr_atual'];
$tabela .= '<tr>';
$tabela .= '<td>'.$nome.'</td>';
$tabela .= '<td>'.$sld_dev_ctbl.'</td>';
$tabela .= '<td>'.$saldo.'</td>';
$tabela .= '<td>'.$vlr_atual.'</td>';
$tabela .= '</tr>';
}
$tabela .= '</table>';