查询结果重复

$query="Select distinct * from voucher_payment LEFT Join vouchers ON voucher_payment.voucher_id = vouchers.voucher_id LEFT JOIN payment_details ON voucher_payment.payment_id= payment_details.payment_id where paid_amount > 0";

$result = pg_query($conn,$query);

<th>File Name</th>
<th>Date Recieved</th>




</tr>
</thead>
<?php 

while($row = pg_fetch_array($result))
{
$servicedate=$row['service_dos']; 
$code= $row['cpt_code'];
$servicedate= substr($row['service_dos'],0,4) . "-". substr($row['service_dos'],4,2). "-". substr($row['service_dos'],6) ;

$query2="Select * from charge LEFT Join payment ON charge.charge_id = payment.charge_id where charge.cpt_code NOT LIKE '" .$code  . "' AND charge.charge_treatment_date != '" .$servicedate  . "'";
$result2 = pg_query($conn2,$query2); 
$row2= pg_fetch_array($result2);


?>

<tbody>


<tr>

<td><?php echo $row['file_name']; ?></td>
<td><?php echo $row['parsing_date']; ?></td>

The outcome are:

File name                Date
---------               --------
2943875897               2016-07-08
2943875897               2016-07-08
2943875897               2016-07-08
2943875897               2016-07-08

And so on, I put distinct but still the same results just different names, can anyone tell me what seems to be the issue? I also wanted to GROUP BY thinking it would help but it didn't.